how can extract part of image

hi i want to extract red region from my image.please help me.i attached it

 Accepted Answer

Image Analyst
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

i have original image but i dont know how attach it in this comment
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
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.
this image was original image.youre demo detection every color such as red,green and etc.but i have extract Total area under the toes that include several colors.i have just inside the area marked.
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(:));
I'm really confused and dont know how i get this part of image by this code. i extracted heel of this image but i dont extract upper part of footprint image by matlab code
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
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
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.
yes in firs post.not important that this region is far away from the red region.i want just extract this region.my friend write me a code that extract heel of foot.i dont know how defined it.
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.
fereshte
fereshte on 13 Jun 2014
Edited: fereshte on 13 Jun 2014
yes thanks alot just this cropped image is very small.can you help me to have a big area in this part such as red region in inital image?
Yes it is small. If you want to resize it for some reason, you can use imresize().
no.My goal is to obtain the total area under my big toe like the area that I've marked in red.marked region in binary image is very small area.
fereshte
fereshte on 13 Jun 2014
Edited: fereshte on 13 Jun 2014
i attached my purpose.i want this region of footprint in cropped image of youre code
dear Image Analyst can you help me?
Use my code to ask regionprops() for the 'Area' also.
fereshte
fereshte on 14 Jun 2014
Edited: fereshte on 14 Jun 2014
i dont know how set thersholding.i change thershold but i couldnt access to purpose region.
how change it to obtain purpose region?
measurements = regionprops(labeledImage, 'BoundingBox');
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
Just add in any additional measurements you want it to take.
ok.thanks.how convert binary image to color image?
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.
is it possible in the code that outputs be colored at all stages instead of binary image?
What is a "stage"?
meaning outputs in all youre code
same binary image but with main colors.i want to processing on colored extraction parts and dont need to binary image same heel image i want convert binary image to colored image
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.
youre code is true but output was binary. i enter colorImage = cat(3, binaryImage, binaryImage, binaryImage) in code but dont give me the image with the original colors.
:(
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
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)
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?
The part where to use the mask,convert to color image. I had a change in your program and get a binary image. I want white region convert to original colors and black parts remain the same.

Sign in to comment.

More Answers (0)

Asked:

on 10 Jun 2014

Commented:

on 18 Jun 2014

Community Treasure Hunt

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

Start Hunting!