I have to spread rice grains on a sheet and then find the average length of the rice grains spread. Any ideas how to do this in MATLAB?
sounds like homework but here are some ideas
look at regionprops
in the image processing toolbox.
there are a bunch of properties it can help you find, 'majoraxislength'
may be apropriate.
If you have a good contrast between the background and the rice, you can follow a simple (though naive algorithm) recipe (I don't remember the commands in Matlab but it will be easy using the help)
1 - Threshold
2- Component Labeling
3- Get the length of each component (as pointed by @second) and use it to reckon the average size.
This exact situation can be found as an image processing example in the online MathWorks documentation for the Image Processing Toolbox:
Seriously, they use a picture of rice grains and everything! The only difference would be that you would want to look at a different property of the image when using the function REGIONPROPS, probably the 'MajorAxisLength'
property (which requires using the labeled
matrix from the example).