Trying to find the error in logic

1 visualización (últimos 30 días)
Rida Memon
Rida Memon el 2 de Mzo. de 2020
Comentada: Rida Memon el 3 de Mzo. de 2020
There is some problem in the logic of this code. It is supposed to segment the lungs from chest radiographs for the set threshold but it is not doing that correctly (providing same results for any threshold value).
clear; clc; close all;
%% Loading images
Threshold = 240;
raw_x_ray='ee.png';
I=imread(raw_x_ray);
figure(101);
imshow(I);
colormap(gray);
title('Grayscale X-Ray');
I=wiener2(I, [7 7]);
figure(102);
subplot(2,1,1);
imshow(I);
subplot(2,1,2);
imhist(I, 256);
a_thresh = I >= Threshold; % set this threshold
[labelImage, numberOfBlobs] = bwlabel(a_thresh);
props = regionprops(a_thresh,'all');
sortedSolidity = sort([props.Solidity], 'descend');
SB = sortedSolidity(1);
if SB == 1
binaryImage = imbinarize(I); figure(103);
imshow(binaryImage); colormap(gray);
SE = strel('square',3);
morphologicalGradient = imsubtract(imdilate(binaryImage, SE),imerode(binaryImage, SE));
mask = imbinarize(morphologicalGradient,0.03);
SE = strel('square',2);
mask = imclose(mask, SE);
mask = imfill(mask,'holes');
mask = bwareafilt(mask,2); % control number of area show
notMask = ~mask;
mask = mask | bwpropfilt(notMask,'Area',[-Inf, 5000 - eps(5000)]);
showMaskAsOverlay(0.5,mask,'r'); % you have to download app/function showMaskAsOverlay
BW2 = imfill(binaryImage,'holes');
new_image = BW2 ;
new_image(~mask) = 0; % invert background and holes
B=bwboundaries(new_image); % can only accept 2 dimensions
figure(104);
imshow(new_image);
ss = strcat('Result_',num2str(Threshold),'.mat');
save(ss,'new_image');
hold on
visboundaries(B);
im8 = im2uint8(new_image);
imwrite(im8, 'ccc.png')
end
  2 comentarios
John Petersen
John Petersen el 2 de Mzo. de 2020
It would help if you could narrow it down a little more and maybe explain what is wrong about it?
Rida Memon
Rida Memon el 2 de Mzo. de 2020
The code is providing same output for any threshold value be it 90,110 or 250 etc.. I feel the problem is in these lines: SB = sortedSolidity(1); if SB == 1

Iniciar sesión para comentar.

Respuestas (1)

Daniel Vieira
Daniel Vieira el 2 de Mzo. de 2020
Editada: Daniel Vieira el 2 de Mzo. de 2020
the Threshold parameter doesn't matter at all in your code. you binarize the image with the threshold, measure solidity of blobs, take the largest solidity, and if it's 1 (which is extremely likely) then you throw the previous binarization away and binarize again with default values of imbinarize. I'm not sure that's what you intended to do, but to me it seems unntentional, I don't think this approach goes anywhere.
  1 comentario
Rida Memon
Rida Memon el 3 de Mzo. de 2020
Actually i have picked that code from a site. I understand that there is above stated problem with this code. Therefore i need help to correct this code. It should not throw but use that previously obtained threshold. Kindly help me if you can.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by