Prev: blstheta(Price,Strike,Int_Rate,Time,Volatility)
Next: how to find the rotation angle of two template?
From: ImageAnalyst on 28 May 2010 10:21 On May 28, 7:49 am, "Bruno Luong" <b.lu...(a)fogale.findmycountry> wrote: > ImageAnalyst <imageanal...(a)mailinator.com> wrote in message <f8f2544d-6e99-4d3f-a1e0-ec0f29707...(a)k31g2000vbu.googlegroups.com>... > > Arun: > > Can you threshold your image to get a binary image of the circular > > area? That would be the first step. Then find the centroid and the > > three points closest to the centroid, and you're practically done. > > If the circular happens to be a perfect disc, any point in the circumference is the closest to the centroid, no? And the set of the centroids any three points located on the circle is the disc itself, no? > > It seems this method is not very robust, at least for the circle. > > What about find the biggest (has largest radius) circumscribed circle of all Delaunay triangles of the set of the points on the *boundary* of the object? > > Bruno -------------------------------------------------------------------------------------------------------------- Bruno: Since this is digitized on a discrete matrix, not all perimeter coordinates of the "circle" will lie the same distance from the centroid (even if it were a "perfect" circle but certainly not for whatever approximately circular shape that his MRI object may have). There may be several (but definitely not all) that are the same distance. Using any three points will define a circle, using the circumscribed circle formula. Arun said he wanted the "largest possible circle that could be fit into the image of the circular object" - I believe the key word being "into." So in other words he has a bunch of perimeter points obtained from a fairly circular object and he wants the largest circle that can fit INTO those points. To do this you'd first find the centroid of the entire circular area, then simply take the three perimeter points that are CLOSEST to the centroid and pass those points into a formula such as this http://en.wikipedia.org/wiki/Circumscribed_circle I believe this is accurate for fairly circular shapes but would not work for shapes where the centroid is outside the object (such as an object shaped like the letter "C"), or very close to the perimeter. For those bizarre shapes, you could use morphology to compute the "ultimate eroded set" and then do a few more steps. What you suggested is like what you suggest but I believe you're suggesting a method to find the SMALLEST circle that circumscribes the OUTER perimeter points - the opposite of what I suggested. If he wanted to do that instead of finding the largest inner circle, he could take the convex hull and then use the circumscribed circle formula again (I don't see how computng the triangles is necessary). On the other hand, if he really wanted the best FIT to ALL the coordinates rather than the largest inside or smallest outside circle then neither of us is right. Arun, you can use bwlabel and regionprops to locate the centroid. thresholdValue = 100; binaryImage = originalImage > thresholdValue; % Bright objects will be the chosen if you use >. % Do a "hole fill" to get rid of any background pixels inside the blobs. binaryImage = imfill(binaryImage, 'holes'); labeledImage = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it % Get all the blob properties. Can only pass in originalImage in version R2008a and later. blobMeasurements = regionprops(labeledImage, originalImage, 'all'); I demonstrate how to find centroids (of circular coins) in my image analysis demo. http://www.mathworks.com/matlabcentral/fileexchange/25157 -ImageAnalyst
From: Arun Kook on 28 May 2010 10:36 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <0e13b52b-73fe-4185-afb7-b288b7f911e0(a)y21g2000vba.googlegroups.com>... > On May 28, 7:49 am, "Bruno Luong" <b.lu...(a)fogale.findmycountry> > wrote: > > ImageAnalyst <imageanal...(a)mailinator.com> wrote in message <f8f2544d-6e99-4d3f-a1e0-ec0f29707...(a)k31g2000vbu.googlegroups.com>... > > > Arun: > > > Can you threshold your image to get a binary image of the circular > > > area? That would be the first step. Then find the centroid and the > > > three points closest to the centroid, and you're practically done. > > > > If the circular happens to be a perfect disc, any point in the circumference is the closest to the centroid, no? And the set of the centroids any three points located on the circle is the disc itself, no? > > > > It seems this method is not very robust, at least for the circle. > > > > What about find the biggest (has largest radius) circumscribed circle of all Delaunay triangles of the set of the points on the *boundary* of the object? > > > > Bruno > > -------------------------------------------------------------------------------------------------------------- > Bruno: > Since this is digitized on a discrete matrix, not all perimeter > coordinates of the "circle" will lie the same distance from the > centroid (even if it were a "perfect" circle but certainly not for > whatever approximately circular shape that his MRI object may have). > There may be several (but definitely not all) that are the same > distance. Using any three points will define a circle, using the > circumscribed circle formula. > > Arun said he wanted the "largest possible circle that could be fit > into the image of the circular object" - I believe the key word being > "into." So in other words he has a bunch of perimeter points obtained > from a fairly circular object and he wants the largest circle that can > fit INTO those points. To do this you'd first find the centroid of > the entire circular area, then simply take the three perimeter points > that are CLOSEST to the centroid and pass those points into a formula > such as this http://en.wikipedia.org/wiki/Circumscribed_circle > I believe this is accurate for fairly circular shapes but would not > work for shapes where the centroid is outside the object (such as an > object shaped like the letter "C"), or very close to the perimeter. > For those bizarre shapes, you could use morphology to compute the > "ultimate eroded set" and then do a few more steps. > > What you suggested is like what you suggest but I believe you're > suggesting a method to find the SMALLEST circle that circumscribes the > OUTER perimeter points - the opposite of what I suggested. If he > wanted to do that instead of finding the largest inner circle, he > could take the convex hull and then use the circumscribed circle > formula again (I don't see how computng the triangles is necessary). > > On the other hand, if he really wanted the best FIT to ALL the > coordinates rather than the largest inside or smallest outside circle > then neither of us is right. > > Arun, you can use bwlabel and regionprops to locate the centroid. > thresholdValue = 100; > binaryImage = originalImage > thresholdValue; % Bright objects will be > the chosen if you use >. > % Do a "hole fill" to get rid of any background pixels inside the > blobs. > binaryImage = imfill(binaryImage, 'holes'); > labeledImage = bwlabel(binaryImage, 8); % Label each blob so we > can make measurements of it > % Get all the blob properties. Can only pass in originalImage in > version R2008a and later. > blobMeasurements = regionprops(labeledImage, originalImage, 'all'); > > I demonstrate how to find centroids (of circular coins) in my image > analysis demo. > http://www.mathworks.com/matlabcentral/fileexchange/25157 > > -ImageAnalyst > > Image Analyst Many thanks for your help. I am nearly done with the solution using the way you described. I am new to matlab and image processing in general, thus was trying figure out how i would find the centroid of the object. I managed to do that using this s = regionprops(L, 'Centroid'); Now i am trying to find the three points on the object that are the shortest distance. Thanks again Arun
From: ImageAnalyst on 28 May 2010 10:51 On May 28, 10:36 am, "Arun Kook" <arun_k...(a)yahoo.co.uk> wrote: > Image Analyst > Many thanks for your help. I am nearly done with the solution using the way you described. I am new to matlab and image processing in general, thus was trying figure out how i would find the centroid of the object. > > I managed to do that using this > s = regionprops(L, 'Centroid'); > > Now i am trying to find the three points on the object that are the shortest distance. > > Thanks again > Arun- -------------------------------------- You can use bwboundaries (like in the demo) and hypot() inside a simple for loop for that if you want. Should be very fast. Or you can use a vectorized method. Both are lightning fast since you probably only have a few thousand points. Whatever is easiest and most intuitive for you... Just to make sure, you do want the largest inscribed circle, right, not the best fit to all the boundary points, right? -ImageAnalyst
From: Bruno Luong on 28 May 2010 10:52 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <0e13b52b-73fe-4185-afb7-b288b7f911e0(a)y21g2000vba.googlegroups.com>... > Since this is digitized on a discrete matrix, not all perimeter > coordinates of the "circle" will lie the same distance from the > centroid (even if it were a "perfect" circle but certainly not for > whatever approximately circular shape that his MRI object may have). > There may be several (but definitely not all) that are the same > distance. Using any three points will define a circle, using the > circumscribed circle formula. I can't see why "discrete" can escape to avoid the issue. Even the pixel is discrete, there is always a slight chance where the closest points are not disperse, but they fall very close in absolute distance, unless if it has been proven. > > What you suggested is like what you suggest but I believe you're > suggesting a method to find the SMALLEST circle that circumscribes the > OUTER perimeter points - the opposite of what I suggested. No, What I suggested is infact the largest circle that does not cross any pixels other than the three in the triangles. In the code below, OP should replace (x,y) entered by user by the list of pixels coordinates of the circumference (deleted by other means), and we can see it's the largest circle that does not contain any other pixel. function [R cx cy] = circumscribedcircle(x, y) x = x(:); y = y(:); dx = diff(x([2 3 1 2])); dy = diff(y([2 3 1 2])); Ta = abs(det([dx(1:2) dy(1:2)])); l2 = dx.^2+dy.^2; R = prod(sqrt(l2))/(2*Ta); w = l2.*(toeplitz([-1 1 1])*l2); w = w/sum(w); cx = w.'*x; cy = w.'*y; end % circumscribedcircle %% Script clf; npnt = 20; fprintf('Use the mouse and enter %d points on the circumference\n', npnt); [x y] = ginput(npnt); %% Engine tri = delaunay(x,y); getR = @(i) circumscribedcircle(x(tri(i,:)), y(tri(i,:))); [R cx cy] = arrayfun(getR, 1:size(tri,1)); % wee need this to avoid circle that encloses concave boundary points in = inpolygon(cx, cy, x, y); in = find(in); [~, imax]=max(R(in)); % largest radius of the circle imax = in(imax); tx = x(tri(imax,:)); ty = y(tri(imax,:)); [Rmax cx cy] = circumscribedcircle(tx, ty); % Graphic check theta = [linspace(0,2*pi) 0]; plot(x([1:end 1]),y([1:end 1]),'ro-'); hold on plot(cos(theta)*Rmax+cx,sin(theta)*Rmax+cy) axis equal % Bruno
From: ImageAnalyst on 28 May 2010 11:45 Bruno: Apparently I misinterpreted your comment "find the biggest (has largest radius) circumscribed circle of all Delaunay triangles of the set of the points on the *boundary* of the object" because when I ran your code, it does work to find the largest inside circle. Sorry about that - it's nice work.
First
|
Prev
|
Pages: 1 2 Prev: blstheta(Price,Strike,Int_Rate,Time,Volatility) Next: how to find the rotation angle of two template? |