Image Segmentation not working properly

I have written a code to identify the green and black color seeds and then calculate the ratio of the area occupied by green seeds to that of black seeds. I used the color thresholder app to identify the two colors and generated 2 functions- one to segment the green color and another to segment the black. I saved the 2 segmented images in Binary format. Then I found each of the area using bwarea() and hence found out their ratio.
However, the result so obtained is not accurate. For 50:50 ratio (black:green), I get 42:68 and for 70:30, I get 40:60.
Also I am unable to use this function on other similar images with different seeds proportion. Displaying both the binary images using imshowpair(bImg, gImg, 'falsecolor'), I get :
Please tell me where I have gone wrong and what is the solution? Thank you.

10 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 24 日
Still remembered @Image Analyst Sir had advised you, have you followed?
Shashank
Shashank 2018 年 9 月 24 日
Sorry what? I don't get you.
Image Analyst
Image Analyst 2018 年 9 月 24 日
I do remember coding up a demo for this beans image recently. But I don't see it under Shashank's posts, so either it somehow got deleted or someone else with the same photo asked the same question (if so, is it a homework assignment?).
Shashank
Shashank 2018 年 9 月 24 日
No sir it is not an assignment. I am studying the degree of mixing of these seeds in a gas-solid fluidized bed. So to calculate and verify the mixing factor, I am using Image Analysis. Could you please let me know if this is the correct method to approach or is there some other better way? Thank you.
Shashank
Shashank 2018 年 9 月 24 日
@Image Analyst Sir, he is my group mate. We are together working on this project to study the degree of mixing. I couldn't understand the method that you have used in the demo, so I tried using a different method but still did not get the result. Please help me learn as I am new to Image Processing. Thank you.
Image Analyst
Image Analyst 2018 年 9 月 24 日
See attached demo on k-means. You should have a known number of classes, like 3 for white, black, and green. But after color segmentation you'll still have to do some spatial cleanup because of shadows, white specks on the seeds, specular reflections, etc.
Shashank
Shashank 2018 年 9 月 25 日
I used the code and got a result like this.
What I am thinking is, is there a way to superimpose "Class 2 Image Masking Original" and "Class 5 Image Masking Original" so that we can find the area occupied by each color seed? Then we could determine the ratio of their areas?
Image Analyst
Image Analyst 2018 年 9 月 25 日
Yes, you can OR the masks to combine classes
mask25 = mask2 | mask5;
Shashank
Shashank 2018 年 9 月 25 日
Is this the correct way to extract mask-2 and mask-5 from the for loop? If not, how should I extract them?
for c = 1 : numberOfClasses
subplot(3, numberOfClasses, c + numberOfClasses);
thisClass = allClasses(:, :, c);
imshow(thisClass);
caption = sprintf('Image of\nClass %d Indexes', c);
title(caption, 'FontSize', fontSize);
maskedRgbImage = bsxfun(@times, rgbImage, cast(thisClass,
'like', rgbImage));
subplot(3, numberOfClasses, c + 2 * numberOfClasses);
imshow(maskedRgbImage);
if c==2
x = maskedRgbImage;
end
if c==5
y = maskedRgbImage;
end
caption = sprintf('Class %d Image\nMasking Original', c);
title(caption, 'FontSize', fontSize);
% Make indexed image
indexedImageK(thisClass) = c;
end
mask25 = x | y;
imshow(mask25);
if true
% code
end
PeterHaultan
PeterHaultan 2018 年 10 月 7 日
Does this help?
I = imread('lena.jpg');
I = rgb2gray(I);
[r,c] = size(I);
L = kmeans(I(:),5);
I = reshape(L,[r,c]);
mask25 = (I==2)|(I==5);

サインインしてコメントする。

回答 (0 件)

製品

リリース

R2017b

質問済み:

2018 年 9 月 24 日

コメント済み:

2018 年 10 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by