Cropping Irregular Images on MatLab

8 visualizaciones (últimos 30 días)
Aya Zaatreh
Aya Zaatreh el 28 de Nov. de 2023
Comentada: Cris LaPierre el 29 de Nov. de 2023
Hi! I am working on a project which involves finding color saturation on a menstrual pad. I want the Matlab code to eliminate the background area of any picture and only read the colors from inside of the pad. I can only figure out how to do a crop feature for one specific image, but I dont know how to generalize the code to work for any picture. Any help would be appreciated! Thank you!

Respuestas (2)

Cris LaPierre
Cris LaPierre el 28 de Nov. de 2023
  3 comentarios
Image Analyst
Image Analyst el 29 de Nov. de 2023
I told you below. Scroll down.
Cris LaPierre
Cris LaPierre el 29 de Nov. de 2023
I'd point you to our Image Processing for Engineering and Science Specialization. It's free to enroll, and takes you through some common workflows that may help you.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 28 de Nov. de 2023
Believe it or not I've done this. Worked on it for many, many years and it's been in production use for over 20 years.
Now the simplistic way would be to use the Color Thresholder app on the apps tab of the tool ribbon and operate in HSV color space and then threshold on the Saturation channel. Bright, vivid colors have high saturation, like more than .25 or .3, while neutral (white, black, gray) shades have low saturation (below 0.25). Export the function and incorporate it into your code. Then you can find the colors within the mask. You don't need to crop it but you should use LAB color space, not RGB. And you should calibrate to a Color Checker chart. Otherwise your color values are all arbitrary and could change from one snapshot to the next. Something like
mask = createMask(rgbImage);
labimage = rgb2lab(rgbImage);
[lImage, aImage, bImage] = imsplit(labImage);
meanL = mean(lImage(mask))
meanA = mean(aImage(mask))
meanB = mean(bImage(mask))
No cropping is necessary because by using the logical mask image as logical indexes, it will extract all the pixels inside the mask as a 1-D list of gray levels, which mean() will get the mean of.
Eventually you'll find that it is not detecting all the stained areas so well. And there are a couple of reasons for that. One is that some stains are very dark, like dark brown or red or black, and their saturation value is not very high so they are not detected as a colored area. Another is that some stains are very light ("brush off") and it's basically a judgment call as to where to put the dividing line between white pad and light stain.
Another problem is that the gamut of stains is not one that can easily be carved out by threshold planes in HSV color space or any color space. That is because the boundaries between stain and non-stain are not planes and the gamut you want is irregularly shaped, not like a truncated wedge of a cone which is what you'd get thresholding in HSV color space.
So what to do? What you can do is to use a discriminant color classifier on the LAB image data. That will be able to carve out irregularly shaped gamut. What you do is manually trace around your classes on a bunch of images to build up a training set of LAB color triplets that define different classes like background, pad, stain, ink, etc.
See attached demo. Below I trained it on 3 classes and chose 5 different classifier models so you can see how they differ a little bit.
  1 comentario
Image Analyst
Image Analyst el 28 de Nov. de 2023
Just a followup. If you're trying to measure the fairly uniform ink artwork on the pad (pink or blue floral patterns for example), then thresholding in HSV color space might work, but for real world stains, it won't work.

Iniciar sesión para comentar.


Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by