If ROI is already outlined how to mask ROI without using imfreehand function output parameters?

I have detected the region of interest in an image without using imfreehand function. Now I want to mask inside the ROI which I have outlined in red line as shown in below image. http://img534.imageshack.us/img534/4272/output3l.jpg
I am stuck up with following part of code.
hFH = imfreehand();
binaryImage = hFH.createMask();
xy = hFH.getPosition;
I dont want to use imfreehand as I have already detected ROI. So in above code what should I assign to hFH?
Can somebody please help me with this? Thanks in advance for your help!

3 comentarios

In simple words I dont want to use "imfreehand" function as I have already detected & outlined "Region of Interest" (ROI) in the image. Now the problem is I want to know what are the output values of imfreehand so that I can find out the similar values from the "Region of Interest" from my image & can use them in order to apply the mask on it.
hFH = imfreehand();
What will hFH contain (I mean to say which values of ROI drawn using imfreehand) ?
I hope this time it is much clear than the earlier one. Thanks in advance!
hFH would be an object inherited from the imroi class, and the methods available for it are
methods imfreehand
As far as I understand your question, you are trying to compare pixel values from your ROI with a freehand ROI using imfreehand? Would that not be possible by just an and between the ROI and your image?
Yes you are partially right. My intention here is to mask the ROI which I have already detected using Random Walker algorithm (& obviously without using imfreehand). If I could able to mask the ROI it would be helpful to proceed further for calculations such as Area, Centroid, Perimeter etc. It would be a great help if somebody could help me to mask the ROI as discussed above.

Iniciar sesión para comentar.

 Respuesta aceptada

I'm not sure what you're asking. What is "the ROI" - the area you drew with imfreehand(), or the white binary blob inside that, or the whole image?
And what does " the similar values from the "Region of Interest"" mean? Do you mean the gray levels in that ROI?
I don't understand what you're going to "apply the mask" to? What is the mask anyway? Is it the same as the ROI, or is it something else?

9 comentarios

Region of Interest (ROI) - The outlined part in red line. http://img534.imageshack.us/img534/4272/output3l.jpg
Now If I use imfreehand on original image I have to draw ROI manually which I dont want as I have already detected ROI (shown in red line in above image ). My motive is to mask the outlined ROI (or in other words highlight the ROI) & also want to calculate Area, Centroid, Perimeter etc of ROI.
If I apply imfreehand () on original image & draw Region of Interest I can apply mask on ROI as follows
hFH = imfreehand(); % Create a binary image ("mask") from the ROI object. binaryImage = hFH.createMask(); xy = hFH.getPosition;
My assumption is if I could able to pass the values to hFH from ROI (Red line) like the one used from imfreehand function hFH = imfreehand(); I can create mask of ROI which I have detected. Can you please share your ideas?
Perhaps this code (that I posted for someone else) will help you: http://www.mathworks.com/matlabcentral/answers/58000#answer_70252 It does masking and extracting. If you need more, please explain better what you need.
Thanks for the code it fulfills the purpose of calculating Area, Centroid, Perimeter etc of ROI (drawn using imfreehand); simply the code really works great excluding the following point
1) imfreehand() is used to select the Region of Interest manually but as I have already outlined region of interest I dont want to manually select the ROI using imfreehand.
Original image with ROI outlined in red color (There are inner & outer red lined part; ROI is the part inside the outer red outline this includes every pixel within it including the inner outline as well) http://img203.imageshack.us/img203/7049/output2.jpg
hFH = imfreehand(); % Create a binary image ("mask") from the ROI object. binaryImage = hFH.createMask(); xy = hFH.getPosition;
If I dont use imfreehand() how can I find out the values from ROI (which I have outlined in red) & assign the same to hFH & proceed further for creating mask of ROI (only ROI will be highlighted & rest of the image will be blacken)
binaryImage = hFH.createMask(); xy = hFH.getPosition;
Thanks in advance for your help!
How did you make the red? Do you have the coordinates of it? Or are you starting with an RGB image? If so, why? Why don't you have the coordinates of the red already, in which case you can use polyarea()?
I have used Random Walker algorithm to detect the left ventricle's inner & outer wall (Outlined in red lines) based on the seed points. I am done with this part; now I want to calculate the area, centriod & perimeter of the left ventricle (Outer part clolored in red line). If I use your code & draw a outer wall of left ventricle I am able to easily calculate area etc. In your code how can I skip imfreehand() function and instead pass the values from left ventricle's outer wall (outer red line) from my image ? The remaining part of your code that calculates area, centriod, perimeter etc is based upon output values of imfreehand () hFH = imfreehand(); I want to assign the similar values from left ventricle's outer wall (outlined in red) so that I can proceed further with your code. Thanks for your help!
Did you look at polyarea() yet? I don't know what the "Random Walker algorithm" is but if it produces a list of x and y coordinates (which I believe it must otherwise it wouldn't be able to turn those pixels red) then you can just do
area = polyarea(x, y);
Or, since you need to get a bunch of other measurements, you can do
binaryImage = polymask(x, y, rows, columns);
measurements = regionprops(binaryImage, 'Area', 'Centroid', 'Perimeter');
The Random Walker Algorithm logic is based on seed points calculated by various algebraic formulas which is much complicated in the first place.
I am not an expertise in Matlab but moreover a novice struggler in it. Let me put it in a simpler manner.
1) I have an input image wherein a irregular part is outlined in red color 2) At this point I dont know its x.y coordinates. How can I calculate Area, Centriod, Perimeter etc. of the red outlined part in the image?
Thanks for your help in advance!
If somebody masked the image like that, and saved it as an RGB image, then you need to find the red:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Find the outline by itself.
redOutline = (redChannel == 255) & ...
(greenChannel == 0) & ...
(blueChannel == 0);
% Fill it in
filledRedMaskImage = imfill(redOutline, 'holes');
% Count pixels
areaInPixels = sum(filledRedMaskImage (:));
I tried it on my image and worked like a magic. Thanks a Million!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by