apply region growing code to my image
Show older comments
Hi! I am using this code (see link) although it is a bit old. The example given by the author works:
load example
figure, imshow(cIM, [0 1500]), hold all
poly = regionGrowing(cIM, [], 300); % click somewhere inside the lungs
plot(poly(:,1), poly(:,2), 'LineWidth', 2)
I would like to do the same with my image (example_my.jpg) getting the output on the right.

Is there any parameter I should change?
It always leads me to an error but I can't find a solution.
cIM_1 = im2double(imread('example_my.jpg'));
% grayImage = rgb2gray(cIM_1);
% J = im2uint16(grayImage);
% imshow(J)
figure, imshow(cIM_1, [0 1500]), hold all
poly = regionGrowing(cIM_1, [], 300); % click somewhere inside the lungs
plot(poly(:,1), poly(:,2), 'LineWidth', 2)
10 Comments
Rik
on 27 Jan 2023
That code was last updated 12 years ago.
It didn't warn you that it was treating your image as 3D. I don't fully understand what it is trying to do with the axis2pix function, so I can't easily debug that for you.
I would suggest using my RegGrow function instead, and salvage the second loop that converts the volume to a polygon. Note that my function will also treat your image as 3D unless you convert it explicitly to 2D.
Alberto Acri
on 27 Jan 2023
cIM_1 = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1275885/example_my.jpg');
mask = RegGrow(cIM_1(:,:,1),'seed',[188 114],'MaxDiff',20);
That will give you a binary mask of the area marked in your question:
imshow(imfuse(cIM_1(:,:,1),mask))
Now you only need to fill the mask and determine a polygon, for which you can use the code in the submission you already found.
Rik
on 27 Jan 2023
Did this solve your issue? Which part should I move to the answer section? Or do you have questions remaining?
Alberto Acri
on 27 Jan 2023
Rik
on 27 Jan 2023
I don't understand exactly what you want to do, but perhaps you mean that you want to merge the masks? You can do that easily with the pipe symbol (i.e., |), since those masks are simply logical arrays.
Alberto Acri
on 27 Jan 2023
Image Analyst
on 27 Jan 2023
Not sure why you even need to do region growing. My simple thresholding method, shown below in the Answer section, works fine to get those two blobs.
Alberto Acri
on 1 Feb 2023
Rik
on 1 Feb 2023
You might need to round the coordinates to make the indices valid.
Accepted Answer
More Answers (1)
Benjamin
on 29 Jan 2023
Edited: Image Analyst
on 29 Jan 2023
0 votes
Region growing is a way to divide an image into smaller parts based on where different colors or shapes are found. It's like selecting starting points to divide the image into.
Categories
Find more on Image Processing Toolbox 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!
