From: Gavin on 11 Jun 2010 21:36 > If you want to plot the major axes of the ellipse, I can't help you. I'm trying to do the same myself and can't figure it out! Only the length, not the co-ordinates of the axis are in the output. But surely this info has to be available to obtain the orientation of the major axis!! If anyone has any suggestions let me know! > Aisling I did this once. I believe I found the centroid (center of mass) of the object (using a binary image) first. Then I made a for loop for values of Theta, the angle of a line passing through the centroid. I algebraically solved for the endpoints of a line each step with a slope of theta and passing through the centroid, such that the endpoints were right on the edges of the image matrix. Then I used a third party .m file to actually draw a line between the two endpoints onto my binary image, so that any pixels where the line intersected the object would have a value of 2, not 1. Then I did an >>image = image > 1; filter, and ran a find(image,1,'first') and find(image,1,'last') to determine the coordinates of the outermost intersections between the drawn line and the object. Whatever the longest distance is across all the thetas you test (sample with whatever precision you like) is the length of the major axis, and you would have the endpoints, too. Then for the minor axis, rotate the image so that the major axis is straight up and down. Then just search each row to find the one with the widest width, and that's your minor axis (with coordinates, once you translate them back to the original rotation). On my machine, this algorithm runs faster than matlab's MajorAxis thing, and gave more accurate results, too (major axis often gave me an answer hundreds of pixels smaller than I could find by hand...)
|
Pages: 1 Prev: Problems initializing structure of structure. Next: Random Generator through mex |