how to crop the red region in an image
3 views (last 30 days)
Show older comments
Dina Ragab
on 11 Jun 2017
Answered: Image Analyst
on 11 Jun 2017
I have a mammogram image and in it a red contour, the rgb channels across this contour are changed whereas they are constant all over the other regions. I want to do a for loop to search about this region in the image and crop it. Can anyone help?
0 Comments
Accepted Answer
Image Analyst
on 11 Jun 2017
I'm guessing that it's a mammogram that's had computer graphics (red pixels) burned into the image. To find the pure red pixels, you need to find where the red signal is 255 or 65535, depending on whether it's uint8 or uint16, and the green and blue signals are 0. See this snippet:
% Find pure red pixels, pure green pixels, and pure blue pixels.
maxValue = intmax(class(rgbImage))
pureRedPixels = (redChannel == maxValue) & (greenChannel == 0) & (blueChannel == 0);
pureGreenPixels = (redChannel == 0) & (greenChannel == maxValue) & (blueChannel == 0);
pureBluePixels = (redChannel == 0) & (greenChannel == 0) & (blueChannel == maxValue);
Use the one for red pixels and then call imshow() to see them. If you don't see anything then use
pureRedPixels = (redChannel <= 0.8*maxValue) & (greenChannel == 0) & (blueChannel == 0);
Keep lowering the 0.8 until you start to see something. I'm not sure exactly what color your red is. The initial code assumes red is (255,0,0) or (65535,0,0).
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!