why this code is not working for a slightly diff lungs image?

4 vues (au cours des 30 derniers jours)
Neha Khan
Neha Khan le 7 Juil 2023
below code works fine with only this image for the slightly different image the results are different like the lung mask is shown when only the tumor should be detected without the lungs wall.
I = imread('lungs.jpeg');
gray = rgb2gray(I);
% Apply a 3x3 median filter
J1 = medfilt2(gray);
%Contrast enhancement and new histogram
K = imadjust(J1,[],[],1.5);
level = graythresh(K);
BW = imbinarize(K, level);
SE = strel('disk', 6);
BW2 = imopen(BW, SE);
BW3 = imerode(BW, SE);
BW4 = imdilate(BW3, SE);
clearBorder = imclearborder(BW4, 8);
props = regionprops(BW4, 'Area', 'Eccentricity', 'Perimeter');
% Extract the properties of the first object (assuming there is at least one)
area = props(1).Area;
eccentricity = props(1).Eccentricity;
perimeter = props(1).Perimeter;
% Classification using SVM
% Define the extracted features
features = [area; eccentricity; perimeter];
% SVM classifier
svm_model = fitcsvm(features', {'normal'}, 'KernelFunction', 'linear');
classification_result = predict(svm_model, features');
tumor_region_props = regionprops(BW4, 'BoundingBox');
tumor_box = tumor_region_props.BoundingBox;
tumor_region = imcrop(I, tumor_box);
%Display Results
figure;
subplot(2,3,1),imshow(I),title('Original Image')
subplot(2,3,2),imhist(gray),title('Histogram Of Original Image')
subplot(2,3,3),imshow(K),title('Image After Enhancement')
subplot(2,3,4),imhist(K),title('Histogram Of Enhancement Image')
subplot(2,3,5),imshow(BW),title('Binary Image')
subplot(2,3,6),imshow(clearBorder),title('Extracted Tumor Region')
% Display the classification result
figure;
if strcmp(classification_result, 'normal')
result_str = 'The CT scan image is classified as normal (non-cancerous).';
disp(result_str);
else
result_str = 'The CT scan image is classified as abnormal (cancerous).';
disp(result_str);
end
disp(['Area: ', num2str(area)]);
disp(['Eccentricity: ', num2str(eccentricity)]);
disp(['Perimeter: ', num2str(perimeter)]);

Réponses (1)

Image Analyst
Image Analyst le 7 Juil 2023
Well there could be lots of reasons. Either
  1. your segmentation for the "bad" image didn't work so well.
  2. the trained SVM model didn't have enough data to be trainined on.
  3. the training did not include any images that were segmented like the "bad one".
Also, calling imadjust is totally worthless. The automatic threshold will produce the same binary image regardless if you enhanced the contrast or not.
If you have any more questions, then attach your images (one it works for and one it doesn't work for) with the paperclip icon after you read this:
Also attach the table of predictors you used to train the model and the vector of ground truth value in a .mat file with the paperclip icon.

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by