How to extract color parameters of each rice grain and then how should I compare them?

4 visualizzazioni (ultimi 30 giorni)
I have an image named 50, I have segmented the iamge and obtained label of each object (rice grain). This image contains rice of different varieties and I want to separate them based on their colour properties because they are similar in shape and size. Can anyone explain me which parmateters will help me to distinguish them.

Risposta accettata

DGM
DGM il 10 Feb 2022
Modificato: DGM il 10 Feb 2022
Consider what information is available. The exposure doesn't seem too bad. There are some grains which seem maybe a bit more colorful than others, but it's hard to tell what's meaningful.
First, strip out the background and adjust the levels so that the grain color is more pronounced.
A = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/890025/50.jpg');
A = rot90(A); % i'm just rotating this so it fits better in the web-view
A = imadjust(A,[0.7 1]);
mask = bwareaopen(rgb2gray(A)>128,1000);
A(~mask(:,:,[1 1 1])) = 0;
imshow(A)
Is that enough information to identify which are which? I'm not sure.
Select only the pixels representing the rice grains. Out of this entire population of pixels, is there any salient group information?
mask = imerode(mask,strel('disk',5)); % erode the mask to ignore edge shading
Am = reshape(A(mask(:,:,[1 1 1])),[],1,3);
Amlab = rgb2lab(Am);
for c = 1:3
subplot(3,1,c)
histogram(Amlab(:,:,c))
end
Maybe? It's hard to tell. Of course, that's the entire population of pixels. What if we consider the average color of each grain?
Alab = rgb2lab(A);
[L N] = bwlabel(mask);
graincolor = zeros(N,3);
for b = 1:N
grainmk = L==b;
Agrain = Alab(grainmk(:,:,[1 1 1]));
graincolor(b,:) = mean(reshape(Agrain,[],3),1);
end
graincolor % average color [L a b] for each grain
graincolor = 50×3
69.0426 -9.3356 27.3126 80.1833 -7.5283 30.9029 76.8120 -8.9078 25.2107 78.9900 -7.3287 23.0446 75.2678 -6.4827 22.0959 77.4466 -8.9433 26.8382 82.7059 -8.4911 24.3281 88.5259 -6.4093 18.3634 85.4462 -7.5029 22.2742 87.3065 -9.6987 29.2395
figure
for c = 1:3
subplot(3,1,c)
histogram(graincolor(:,c))
end
Now it looks even less like there's a discernable pattern. What if we just look at where those color points are and try to find a pattern by eye?
figure
plot3(graincolor(:,2),graincolor(:,3),graincolor(:,1),'b.')
grid on
Well, I'm not sure if that really helps either. It's hard to say if I'm getting anywhere since I'm not sure which are which to begin with. Let's just say that there's a group defined by L>90. Let's just select that.
figure
grainmask = graincolor(:,1)>90;
S = regionprops(mask,'centroid');
C = vertcat(S.Centroid);
imshow(A); hold on
for b = 1:N
if grainmask(b)
plot(C(b,1),C(b,2),'bo','markersize',25);
else
plot(C(b,1),C(b,2),'ro','markersize',25);
end
end
Are those the right ones?
  20 Commenti
Image Analyst
Image Analyst il 18 Feb 2022
Hyper spectral could help. Post those images. Take a picture with all one type of rice on the left and all the other type on the right.
I've been designing imaging systems for about 40 years so I know a little bit about it. 🙂 Other than that (using your hyperspectral images) you should have a light booth that excludes ambient light. You should also check the illumination level with a lux meter to make sure it's the same each time. Aim for somewhere between 1000 and 6000 lux. Take a "blank shot" of just the background so you know how the exposure varies with location in the image due to lens shading and light non-uniformities. Then divide your test images by that background image. See attached demo.
But the big problem is your sample presentation. Your rice you said is all mixed together and you don't know which is which. So, using image analysis, let's say you figure out which type each grain of rice is. Now you need to collect those into bags or buckets (each of one type) to separate them. I guess you'd have to do that by hand, which is subject to error. Plus it would be slow and tedious - definitely not a high throughput method where you could sort through hundreds of kg per day. So maybe you could have the rice on a moving belt and analyze just one at a time. Then, depending on what type of rice it is, a blower tube blasts each grain of rice to the right or left (off the belt) into the proper bucket. Then you'd need to have a bucket fill indicator so you can either automatically switch out the bucket or shutdown the system until the user can put in a new bucket.

Accedi per commentare.

Più risposte (2)

Benjamin Thompson
Benjamin Thompson il 10 Feb 2022
You will have to decide how to separate them based on your intended purpose. See the documentation on the regionprops function in the Image Processing Toolbox for a variety of shape measurements that can be calculated. Your image also is grayscale or very nearly so, which means your ability to separate by color will be difficult. Try running the colorThresholder tool on it to create some masks.

Image Analyst
Image Analyst il 10 Feb 2022
How many colors are you seeing there? Because most of us see one : white. In fact it looks like some of the grains might be saturated (overexposed) so they are clipped at 255. If there are two types of rice there you might try hyperspectral imaging. Maybe as some narrow band of light there will be some brightness differentiation.

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by