how to crop the red region in an image

4 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2017-6-11
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 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by