Image Segmentation and Labeling

9 views (last 30 days)
RFM
RFM on 15 Aug 2020
Commented: Image Analyst on 25 May 2022
Dear All,
I am working on DICOM Images provided in the Mendeley Dataset [Source (https://data.mendeley.com/datasets/zbf6b4pttk/2)]. I have done following:-
a. Extracted Mid-Sagittal Views for both T1 and T2 Weighted Images.
b. Performed basic pre-processing for Image preparation.
c. Created BW (Mask) as well as Pseudo Colored Image.
Now I am trying to:-
a. Segment out the Lumbar Vertebrates and Sacrum Vertebrates (Using regionprops)
b. Mark the Centroids on the Lumbar and Sacrum Bones.
c. Assign labels to Image like L1, L2..L5 (Lumbar) and S for Sacrum (I am assuming S1 as Sacrum Bone and ignoring other levels of Sacrum vertebrates).
d. Input the labelled images to Deep Network for training followed by testing/validation, purposes.
Please suggest the best possible practices for image segmentation for this particular problem.

Accepted Answer

Image Analyst
Image Analyst on 15 Aug 2020
What I'd do is first call bwareafilt() to get blobs only with a certain area range. Then ask regionprops() for the bounding box and centroid. If the bounding box height and width are not both in a reasonable range, then throw out those blobs. Hopefully what remains is the square vertebrae. Then you can identify the individual vertebra by the y coordinate of the centroids. Pretty easy but let me know if you can't figure it out.
labeledImage = bwlabel(mask);
props = regionprops(labeledImage, 'Area', 'Centroid', 'BoundingBox');
allAreas = [props.Area] % Inspect this to find the area1 and area2
mask = bwareafilt(mask, [area1, area2]);
props = regionprops(mask, 'Centroid', 'BoundingBox');
bb = vertcat(props.BoundingBox)
widths = bb(:, 3)
heights = bb(:, 4)
aspectRatios = widths ./ heights
keepers = (widths > width1 & widths < width2) & (heights > height1 & heights < height2);
mask = ismember(labeledImage, find(keepers));
labeledImage = bwlabel(mask);
props = regionprops(labeledImage, 'Centroid');
xy = vertcat(props.Centroid)
y = xy(:, 2)
[sortedY, sortOrder] = sort(y, 'ascend')
% Sort x and props the same way, from top to bottom based on y
props = props(sortOrder);
x = props(xy(:, 1));
% Label them with a number
for k = 1 : length(props)
xt = x(k);
yt = sortedY(k);
str = sprintf('Blob #%d', k);
text(xt, yt, str, 'Color', 'r', 'FontSize', 20, 'FontWeight', 'bold')
end
So you can see it's pretty easy. It's untested but only requires a few things to be figured out. Figure out the parameters for width1, etc. and plug them in. Let me know if you have any trouble.
You can use ismember to extract a binary image of only a particular vertebra, like the 3rd one, 4th one, etc. and then save those with imwrite for a training set for your deep learning network for that particular vertebra. Like
thisVertebra = ismember(labeledImage, sortOrder(k));
filename = whatever....
imwrite(filename, thisVertebra);
or whatever.
  13 Comments
Hamza Ayari
Hamza Ayari on 25 May 2022
can you send the mask code for it ?
thank you
Image Analyst
Image Analyst on 25 May 2022
@Hamza Ayari I don't know what code you're asking for. I don't have any vertebrae-finding code.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!