You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how can extract part of image
1 view (last 30 days)
Show older comments
hi i want to extract red region from my image.please help me.i attached it
Accepted Answer
Image Analyst
on 10 Jun 2014
Do you have the original gray scale image, or just this pseudocolored image? If you unfortunately have only the pseudocolored image, see my color segmentation demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
32 Comments
Image Analyst
on 10 Jun 2014
Did you try the green image icon? Or the paperclip icon? And you'd need to give the reader for it since it's probably in some floating point format if it's temperatures. If it's only gray levels, then we can work with that via simple thresholding.
Image Analyst
on 11 Jun 2014
Edited: Image Analyst
on 11 Jun 2014
OK, so you don't have the original image. All you have is a pseudocolored image. So my answer remains as above - use color segmentation like in my demos. My "simple color detection" already does red so there's not much you need to change except the filename.
Image Analyst
on 11 Jun 2014
Find out what black is. Maybe the RGB is [0,0,0] or [23,32,18] or whatever. So extract the color bands.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Then threshold
binaryR = redChannel > 10; % or whatever value you want/need.
binaryG = greenChannel > 10; % or whatever value you want/need.
binaryB = blueChannel > 10; % or whatever value you want/need.
Then combine
binaryImage = binaryR & binaryG & binaryB;
% Then count the number of pixels.
numPixels = sum(binaryImage(:));
Image Analyst
on 12 Jun 2014
What does "extract" mean to you exactly? Do you mean like crop out into a smaller separate image? Or to make measurements with regionprops()? Do you want the whole foot or just the red region? You've said both so please clarify.
fereshte
on 13 Jun 2014
Edited: fereshte
on 13 Jun 2014
ok. i extracted heel from this image to check change of colors in this region.now i want to do for part of the same rectangular area that I have highlighted in red.I want this region only like what I have to Heel.heel image attached.
I want the whole picture become black except for area that marked by red lines.
thank you
Image Analyst
on 13 Jun 2014
You mean the red "box" in the image you first posted above? How are the edges defined? It goes out far away from the red "ball of the foot" region.
Image Analyst
on 13 Jun 2014
Alright, I had some spare time this afternoon and downloaded your image and wrote the attached program for you (test.m in blue below the screenshot image). Can you mark the answer as accepted if this does what you asked for? Thanks.
Image Analyst
on 13 Jun 2014
Yes it is small. If you want to resize it for some reason, you can use imresize().
Image Analyst
on 13 Jun 2014
Use my code to ask regionprops() for the 'Area' also.
Image Analyst
on 14 Jun 2014
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
Just add in any additional measurements you want it to take.
Image Analyst
on 14 Jun 2014
Not sure why you want to do that, but you can convert a binary image into a color image (that's just black and white) by doing this:
colorImage = cat(3, binaryImage, binaryImage, binaryImage);
It will look just like the binary image but it will be color with only two colors: black and white. Kind of useless if you ask me.
Image Analyst
on 17 Jun 2014
What is a "stage"?
Image Analyst
on 17 Jun 2014
I gave you code above that extracts the image with the original colors. If that's not what you meant, then try to find a native English speaker to describe what you want.
Image Analyst
on 18 Jun 2014
A binary image is just one step of my total program. If you look above at the screenshot in the above comment, you'll see an RGB subimage extracted. I gave you the cat() answer though I have no idea why you want to do that. Of course it does not give you the image with the original colors. I gave you code that did that. Why you asked for to convert the binary image into a color image is baffling to me. I don't know why you wanted to do that, and I did not do that in my code, but I gave you the code anyway because you explicitly and specifically asked for it. Again, I don't know why you asked for that or what you want to do with that, especially since I gave you the color image cropped from the original based on the binary image which I used as a mask to determine the cropping rectangle.
fereshte
on 18 Jun 2014
Edited: fereshte
on 18 Jun 2014
i do extract red,green and blue pixels in 3 extracted parts in binary image not only in cropped region. i dont need to crop function.is it possible to use a mask on full of binary image?(to convert colored imge)
Image Analyst
on 18 Jun 2014
I don't know what that means. Do you mean like you want to mask the image so that it remains the full size but just zeros out (blackens) the image outside the mask?
More Answers (0)
See Also
Categories
Find more on Image Processing and Computer Vision in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)