apply region growing code to my image
이전 댓글 표시
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
Rik
2023년 1월 27일
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
2023년 1월 27일
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
2023년 1월 27일
Did this solve your issue? Which part should I move to the answer section? Or do you have questions remaining?
Alberto Acri
2023년 1월 27일
Rik
2023년 1월 27일
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
2023년 1월 27일
Image Analyst
2023년 1월 27일
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
2023년 2월 1일
Rik
2023년 2월 1일
You might need to round the coordinates to make the indices valid.
채택된 답변
추가 답변 (1개)
Benjamin
2023년 1월 29일
편집: Image Analyst
2023년 1월 29일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

