retrieve circle position from equation or data array

3 views (last 30 days)
Hello!
I would like to select a circular region from an image , thus i need to use
h= imellipse(hparent, position) and then create a mask
my problem here is that i don't know how to define the image position from the equation or the array containing the points of the circle.
any help would be really appreciated,
Many thanks :)

Answers (5)

Sean de Wolski
Sean de Wolski on 10 May 2012
imshow(h.createMask)
If you look at the methods() of an imellipse object, it's one of the freebies!
methods(h)

Image Analyst
Image Analyst on 10 May 2012
See my demo for interactive use of imellipse:
% Demo to write an ellipse into the overlay of an image,
% and then to burn those overlays into the image.
%----- Initializing steps -----
% Clean up
clc;
clear all;
close all;
fontSize = 14;
workspace; % Display the workspace panel.
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Display images to prepare for the demo.
monochromeImage = imread('pout.tif');
subplot(2, 3, 1);
imshow(monochromeImage);
title('Original Image', 'FontSize', fontSize);
subplot(2, 3, 2);
imshow(monochromeImage);
title('Draw ellipse in overlay here', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Image Analysis Demo of imellipse() function','numbertitle','off')
%----- Burn ellipse into image -----
% Create elliptical mask, h, as an ROI object over the second image.
subplot(2, 3, 2);
userPrompt = sprintf(' Click and drag out an ellipse.\nDouble click inside of it to accept it.');
uiwait(msgbox(userPrompt));
hEllipse = imellipse(gca); % Second argument defines ellipse shape and position.
% Wait for user to finalize the size and location.
xyCoordinates = wait(hEllipse)
% Create a binary image ("mask") from the ROI object.
binaryImage = hEllipse.createMask();
% Display the ellipse mask.
subplot(2, 3, 3);
imshow(binaryImage);
title('Binary mask of the ellipse', 'FontSize', fontSize);
% Burn white ellipse into image by setting it to 255 wherever the mask is true.
outputImage = monochromeImage; % Re-initialize it.
outputImage(binaryImage) = 255;
% Display the image with the "burned in" ellipse.
subplot(2, 3, 4);
imshow(outputImage);
title('New image with ellipse burned into image', 'FontSize', fontSize);
% Burn black ellipse into image by setting it to 0 wherever the mask is true.
outputImage = monochromeImage; % Re-initialize it.
outputImage(binaryImage) = 0;
% Display the image with the "burned in" ellipse.
subplot(2, 3, 5);
imshow(outputImage);
title('New image with ellipse burned into image', 'FontSize', fontSize);
% Erase image outside of ellipse into image by setting it to 0 wherever the mask is true.
outputImage = monochromeImage; % Re-initialize it.
outputImage(~binaryImage) = 0;
% Display the image with the "burned in" ellipse.
subplot(2, 3, 6);
imshow(outputImage);
title('Image erased outside of ellipse', 'FontSize', fontSize);
  1 Comment
Image Analyst
Image Analyst on 10 May 2012
Oh, I saw your comment after I created this demo for you and posted it, and now know you don't really need imellipse. Oh well, maybe it will help someone else.

Sign in to comment.


Ines laz
Ines laz on 10 May 2012
Hi , thank you for answering,
as I understood to use the methods command i need to create the ellipse object first,
but for now I only have the circle equation and I want to find out how to get the position elements: [left bottom width height]
later i will select this circular object with the imellipse object from the image,
I mean i am stuck here:
mg = imread('pout.tif');
h_im = imshow(img);
e = imellipse(gca,[bottom? left? width? heigth?]);
BW = createMask(e,h_im)
  2 Comments
Ines laz
Ines laz on 10 May 2012
the width and heigth are easy to find: 2*radius,
but how about bottom and left, is there any matlab command that allows me to just retrieve them from the circle data?
many thanks,
Sean de Wolski
Sean de Wolski on 10 May 2012
I'm not clear, you want to position the ellipse somewhere? If so where?

Sign in to comment.


Ines laz
Ines laz on 10 May 2012
here is a better description for my problem:
I want to crop a circular region from an image,
and calculate the mean value of this circle (the mean light intensity of the cirular image),
the use of a rectangle will affect the mean value (beacause the pixels outside the circle will be either 0 or 1)
so i only need to select the pixels inside the circle, any advice please?
many thanks,
  3 Comments
Ines laz
Ines laz on 10 May 2012
okey, but to create the mask i need to use imellipse,
but i don't want to drag the circular object manually,
i just want to know the position parameters that i will use from my circle equation,
i mean i know the center and radius of the circle but i want to know the "bottom" and "left" parameters of the circle,
do you please have any idea about how to get them?
Sean de Wolski
Sean de Wolski on 10 May 2012
Oh! Then don't use imellipse. Use the formula for a circle.
http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F

Sign in to comment.


Ines laz
Ines laz on 10 May 2012
Hi both,
thank you very much for the answers,
here is my suggestion , using the logical circle plotting will make me lose the pixel values inside the circle(as i understood from the code), because the image will become binary,
and the imellipse method requires to know the bottom and left,
so how about mixing both
  • first : trying to determine the intersection point between 2 tangents of the circle
i think the cordinates of this point define the left and bottom properties?
if this is true then i will use the imellipse demo to draw the mask
  • then using the first code to calculate the mean
I = your_image;
mask = the_mask;
the_mean = sum(I(mask))./sum(mask(:))
please tell me if i should go for this option
many thanks :)
  1 Comment
Sean de Wolski
Sean de Wolski on 10 May 2012
You're trying to hard. The binary circle doesn't conatin the pixel values, you're correct. But it can be used to tell you which pixels you care about (What my three lines of code to calculate mean were doing)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!