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!

