Clear Filters
Clear Filters

Segmentation of Lungs from Chest X-Ray Images

1 view (last 30 days)
Kindly help me remove this error from my code. Where do i need to set the dimensions? Kindly explain
CODE:
fid = fopen('JPCLN001.img','r','b'); %image from JSRT dataset
oneSlice = fread(fid, [2048 2048], '*uint16','b');
img = mat2gray(oneSlice, [0,4096]);
img1 = imrotate(img,-90);
figure(101);
imshow(img1);
fclose(fid);
colormap(gray);
title('Grayscale X-Ray');
I=wiener2(img1, [5 5]);
figure(102);
subplot(2,1,1);
imshow(I);
subplot(2,1,2);
imhist(I, 256);
a_thresh = I >= 172; % set this threshold
[labelImage, numberOfBlobs] = bwlabel(a_thresh);
props = regionprops(a_thresh,'all');
sortedSolidity = sort([props.Solidity], 'descend');
SB = sortedSolidity(1);
if SB == 1 % SB only accept solidity == 1 filter out bones
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);
hold on
visboundaries(B);
end
ERROR:
Warning: Image is too big to fit on screen; displaying at 33%
> In images.internal.initSize (line 71)
In imshow (line 309)
In a (line 6)
Index exceeds matrix dimensions.
Error in a (line 21)
SB = sortedSolidity(1);

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 24 Jan 2020
>> whos sortedSolidity
Name Size Bytes Class Attributes
sortedSolidity 0x0 0 double
sortedSolidity is empty array, how can you get the fist index data in the next statement
SB=sortedSolidity(1);

Categories

Find more on Biomedical Imaging in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!