Last time, in my spatial transformations series, I introduced the head-and-shoulders outline that I like to call George (George P. Burdell). Today I want to diverge briefly from my main topic and show how I recently "recovered" George.
George appears in section 5.11 of Digital Image Processing Using MATLAB. While working on the book, I tried to keep all data files and M-files necessary for regenerating the book's figures. I found, however, that I could not locate the data for George's curve that appears in Figure 5.12 and Table 5.3.
After a few minutes of head scratching, I decided to get the curve data by taking a digital snapshot of the figure in the book. Here's a cropped version:
url = 'http://blogs.mathworks.com/images/steve/36/george.jpg';
I = imread(url);
imshow(I)
A little fuzzy and dark, but maybe workable. The first step is to threshold the image. The Image Processing Toolbox function graythresh computes binarization thresholds automatically. It works well for a variety of images.
threshold = graythresh(I); bw = im2bw(I, threshold); imshow(bw)
Now we have a nice fat line. Toolbox function bwmorph has a thinning option, but it works on white (foreground) pixels instead of black pixels. So complement the image:
bw2 = ~bw;
and then thin it. Specify the number of iterations to be Inf so that bwmorph will keep thinning until the lines are a single pixel wide.
bw3 = bwmorph(bw2, 'thin', inf);
imshow(bw3)
Now trace the line using toolbox function bwboundaries.
boundaries = bwboundaries(bw3);
boundaries is a cell array containing one P-by-2 matrix for each object boundary. This image contains only one object, so boundaries contains only one P-by-2 matrix. The matrix has twice as many rows as we need, because bwboundaries traces all the way around the object.
b = boundaries{1};
b = b(1:floor(end/2), :);Finally we are ready to plot the curve.
x = b(:,2); y = b(:,1); plot(x,y) axis ij % Place the origin at upper left, with y values increasing from % top to bottom. axis equal % Set the aspect ratio so that the data units are the same in % every direction. title('George P. Burdell')
Get
the MATLAB code
Published with MATLAB® 7.1



Respected sir,
I am Studying M.Tech At Manonmaniam Sundaranar University.Now i learn Matlab .My interest is Thinning Operation.I dont any knowledge about thinning.so i want to learn more about that concept.you use the default function BWMORPH.but i want how that function work. so please help me, and send the bwmorph function algorithm and code .
Great thanks to you Sir
By
A.Senthil Arumugam M.S.,M.Phil.,M.Tech
Senthil, the documentation for bwmorph has a detailed description of the thinning algorithm used. You can find it here.
hello, I am intrest in hand image segmentation , and I need help in using matlab to find the edge detection than how to compute features extractions likes fingers width, length,angles…..
regards
Moussadek - Can you be more specific about what kind of help you are seeking?
hello,
I need know how to get hand countour signature and how to extract the nine salient point (five valleys and four peaks)in order to measure the length, width and height of the fingers and palm
many thanks
Moussadek - That was more specific, but you’ve posed a nontrivial algorithm development question that involves many aspects of image processing - possibly including preprocessing for noise removal, edge detection, segmentation, feature measurement, classification, etc. I’m afraid that there’s no “get_hand_contour_signature_and_salient_points” function. :-) You’ll need to dig deep into a good image processing book. Some of the Image Processing Toolbox demos, which are available in the product and on our web site, may also be helpful for portions of the problem.
hello,
thank you for replaying,I am looking how to implement the border tracing algprithm (Sonka) using matlab
many thanks
Moussadek - I am not familiar with the Sonka algorithm you mentioned.
Respected Sir,
I want ot implement operation like edge detection, segmentation etc using fuzzy logic.
I short how to do fuzzy image processing using matlab…?
May I request to help me to provide necessary details
thanking you
yours sincerely
minu
I too want to implement operation like edge detection, enhanchement etc using fuzzy logic using matlab.
May I request to help me to provide necessary details
thanking you in advance
hi everyone
I need help on fuzzy edge detection would you please send me some sample m-file of fuzzy edge detector
hazhiriq200@walla.com
thanks
Hazhir - I’m sorry, but I don’t have anything on fuzzy edge detection.
Hello!
while implementing the codes using matlab,the function bwboundaries is not working.
Can anyone help.
Am working on biometric security based on dorsal vein pattern..
First I have to remove the palm region from the background and then the veins.
How can I do this?
Please help
Maleika—Can you be more specific about “bwboundaries is not working”?
Dear Sir,
While typing the above codes I am getting the foll:Undefined function or variable ‘bwboundaries’
Another request: I am working on hand dorsal vein pattern as Biometric: How can I extract the vein pattern.. I have perform the codes you have given for thresholding and it works.
Question2: I have an image.How can I remove the coordinates automatically from the image??
With thanks,
Maleika
Maleika—bwboundaries is a function in the Image Processing Toolbox.
Dear Sir,
I can extract coordinates from an image by using getpts. But the extraction is done manually. Is there any function that I can use to do it automatically?
With thanks,
Maleika
Maleika—Can you be more specific? What kind of points? What distinguishes them from other points in the image?
Hello Sir, I am working on dorsal hand vein pattern to be used as Biometric Security. I have do done the segmentation and remove the background. I am left with the vein pattern. Thus, I need coordinates found in the vein pattern. How can I extract these coordinates?
I have used getpts and thus coordinates are extracted manually. I need to know how we can do the same extraction automatically?
Thanks,
Maleika
Maleika@mdash;Once you have the segmented vein pattern, you may want to use bwmorph(bw,’thin’,Inf) to thin the pattern. Then you can use find to extract the coordinates. If you need an ordered list of coordinates, you could try bwboundaries, but you’ll have to take into account that bwboundaries will trace your thinned vein pixels twice in order to go all the way “around” each thinned component.
Hello Sir!
Thanks a lot.
I don’t have bwboundaries function in my image toolbox.
Can you please give me a link where to obtain this function..
I know I ask too much BUT I am in a real difficulty. That is why I need your help.
Loads of Thanks,
Maleika
Maleika—What version of the toolbox do you have? I believe bwboundaries has been in the toolbox since version 4, released sometime around 2004. You’ll need to upgrade in order to get the function.
hello,
i tried your code above for image of leaf but the result isn’t good.
please if you have another code for more complex image please provide me.
thanks in advance
Huda—There are many techniques that might be applicable. Usually the solutions are very dependent on the particular kind of image data you have. You’ll need to explore different operations. Take a look through examples in the toolbox users guide, the product demos, and image processing textbooks for inspiration.
Hello!
while implementing the codes using matlab,the function bwboundaries is not working
Ramana—Can you be a bit more specific? What exactly did you try, what error messages did you receive, etc.?
hi sir,
i am a final yr student and my project is “feature based face recognition”. i have successfully stepped till extracting the eye region from the face. and now i got struck up with the point of finding inter eye-ball distance.
if the coordinates of eyes are rt1 rt2 lt1 and lt2. i want the distance between rt2 and lt1.
can u please help me in finding the corners of eyes automatically in matlab.
give a clue atleast sir… hope u will give us a solution
hi sir, i have one question.i need to extract some coordinates from a B&W image, because i need to use them o the respective Color image.i saw that bwboundary is not usefull, because it just trace the contour, when i need all the coordinates of the points different from zero!can you help me in some way?does any command exist in matlab(R14) that i can use?thank you too much
marco
Marco—Use find.
thank you very much..i wasn’t thinking about this command in matlab..one more question if it’s possible:now that i got my coordinates, how could i extract from the original image the features belonging just to these coordinates and build an image composed only with these features?
because when i use find, i hace a vector with more than 65k rows, and so Matlab doesn’t allow me to make the operation i want to
Marco—You haven’t given me enough to go on. What operation are you trying to do, how are you trying to do it, and how does MATLAB respond?
i try to explain.i have a B&W image with an object coming from a threshold from an RGB image.now i want to extract the coordinates of this object and represent it in another image, with black pixels as background, and my object( with color pixels) as foreground coming from the original RGB image.for example, i have a green ball in an image, with a threshold i have it in B&W.now i want to extract it from the original image, and showing another image only with this ball, but with its color, no more in white.hope i could explain well!!
Marco,
thanks very..the last question..how can i open more images in the same code, like opening images from marco1 to marco9 and making the same operation for all images??i was thinking something like :
for k=1:9
I=imread(’marco’k’.jpg’);
end
but,of course, it doesnt’t work.
thank you
marco
Marco,
for k = 1:9 I = imread(sprintf('marco%d.jpg', k)); endMarco—See also my post on batch processing.
thanks too much..the only problem i have is that when i finish my processing with my image, the for cicle i have to put it outside the command clear all, so it happens that it erases everything..so now i’m trying to find a wya to do it!!
is it allowed to write something like clear all -g, where g is the only variable that i don’t want to clear??
Helo sir,
The program that u have given on morphological gradient works really fine…but
1)how can one proove mathematically that it finds exactly the true boundaries. Since i am working on medical images the precision is the 1st priority.
2)If one wants to find gradient using 1st derivative how can one do tht?I tried doing it with convolution using sobel,prwitt and laplacian operators but it didnt work out..do you have a better suggestion .
3) How can one find distance between two points in an image
i did it all..thank you very much Steve!!ciao from Italy!!
one more question, far from this discussion..can i find , in these pages, something about HU’method for geometrical moments in binary images?thank you
Marco—I don’t know what that is.
hello sir..!
i am final year student and working on a project to detect whether the driver is drowsy or not. i have developed the code to find the face through the edge detection.and now i need to find the eyes of the drivers, and i am not able to develop the code for it…
here above i have found that one of my friend named sravani (numbered as 27) has developed a code of it..
can i get the required code from her..
i will be thankful to you if you can send me her mail id so i can directly contact her to receive the code
please help me sir i am in great need for it
hi sir,
i am doing a project to find the face in the frame by detecting the skin color, or i need to know how can i modify a frame which only shows the green color of the original picture.
thank you
hello sir ,
i have simple image . i try to plot it in 2D , so i apllied “Tracing George” . but when i plot it i get only a part of my image . i use 400*640 dimensions
Saurabh—It’s not so easy to come up with a precise mathematical definition for “true boundary” in the real world of digital images. You might want to look at the discussion of edge detectors in the book Machine Vision by Davies, which contains a lot of information comparing the relative accuracy of various edge detection methods. That book, or just about any other book on image processing, will also have information about gradient computation using the masks you mention.
Ankur—The Image Processing Toolbox demos include a couple about color segmentation. You might get some ideas from those.
Gaurav—I’m sorry, but I can’t give out e-mail addresses.
Najah—Your question is too vague for me to answer. If you can be much more specific about what you are trying to do, what specific code you used, and what happened, then I might be able to help.
Hi, my name is Patrick Nwaoko and I am a biomedical engineering undergrad. How do you extract a piece of an image from an image that you read into Matlab.
Patrick—Are you looking for a way to extract a submatrix? Then it might look something like this:
This code extracts rows 100-200 and columns 400-600 from the matrix I.
hi sir i m shweta m i m a computer engg student.i want to know how to obtain center of a given round object n to get the coordinates of that center
also if i get pixel values of that center i could find the distance between two round objects.
Shweta—You might find the functions bwlabel and regionprops to be useful.
Hello Steve,
I want to change size of gray scale image,its original pixel size is (256*300).
I want to convert pixel size is(200* 200)and store it on height and width format.How I can do it?
Hello Steve,
I want to know if there is any book specially describing in detail different methods of image segmentation with sample Matlab code using different methods like using region growing methods or edge methods or other complex mathematical methods.Any help in this regard is highly appreciable.
Niranjan—Check out the image processing category listing in the MathWorks Book Program.
Renna—Use matrix indexing to extract a 200-by-200 submatrix, or use imresize to rescale the image.
Hello Steve,
I have resize (256*300*3 uint8) image into (200*200 pixels )using imresize.After using this image it shows following error
“Subscripted assignment dimension mismatch”.
Is imresize is correct method?
Thanks
Renna—The correct method for what? You’ve given me almost no information about what specific thing you are trying to accomplish.
respected sir,
i am trying to find the co-ordinates of a cropped image .
and after processing the image i want to paste the processed image in the same co-ordintates from where it was cropped .
[a,rect]=imcrop(i)is the function i used, but i have no idea how to get the co-ordintates from rect .
please help .
thank you
Amal—The first two elements of rect are the x- and y-coordinates of the upper left corner of the crop rectangle. The second two elements are the width and height, respectively.
Hello,
How I convert gray scale image to rgb format?
Thanks
Suraj—Just duplicate the grayscale image three times in third dimension. You can use repmat or cat.
sir ,
i want to threshold a gray scale image. can u tell me how i can go abt it…
Praveen—
Hello Steve,
I have used command uigetfile to access .txt file,without using name ‘X’ ‘Y’ ‘Angle’, and stored at template file.
How I add name ‘X’ ‘Y’ ‘Angle’ ,to coloum 1, coloum 2, coloum 3 using template file.
Dear Steve,
is there any possibility to set the starting point of the bwboundaries function? I mean, the standard bwboundaries function starts scanning the image from left to rigth and up to down. Can I change this order? I’m working with a human silhouette and I’d like to select manually the first point (e.g.the nose).
Regards.
Mari—You can use the bwtraceboundary function to trace a specific boundary at a specific starting point.
dear Steve.
How can i get the perimeter of the image? as an example, the image of ‘George’. How can i get its perimeter?
Hockchai—You could start with bwboundaries or bwtraceboundary to get an ordered list of pixels on the boundary. Take a look inside regionprops to see how it computes perimeter.
Hello,
I need some explanation about the algorithm of ‘thin’ option for bwmorph. In fact I’m trying to implement in C++ this algorithm, but the explanations aren’t very specific in the bottom of that page http://www.mathworks.fr/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox/images/f3-23960.html&http://www.mathworks.fr/support/product/product.html?product=IP
could you explain me what the ’subfields’ represents end ’subiteration’ too ?
What is the equivalent C code for that type of iteration ?
I tried to find for 7 days… you are my last hope…
Thank you very much.
Regards.
Florent—You might want to look at the journal paper for further details. The complete reference is in the doc, but here it is for your convenience: Lam, L., Seong-Whan Lee, and Ching Y. Suen, “Thinning Methodologies-A Comprehensive Survey,” IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 14, No. 9, September 1992, page 879, bottom of first column through top of second column.
You might also find the MATLAB code in bwmorph useful for understanding “subfield” and “subiteration.”
i need to know the detailed algorithm for bwtraceboundaries. i want how that function works. so please help me, and send the bwtraceboudaries function algorithm and code .
Great thanks to you Sir
M.S.—Code for the bwtraceboundaries function ships with the Image Processing Toolbox.
Hey…
Is there a thinning alogrithm around that doesn’t only use the binary threshold but also weights the pixel according to their threshold values?
I need it to find intersecting ridges in a greyscale image and bwmorph doesn’t really work well :-(
Thx Felix
Felix—There are some published grayscale thinning algorithms, but I am unfortunately not familiar with them.
Hi Steve,
the example you provided here shows nicely how to extract a single line from a object. What happens when I have an object that may be present by a network or several polygons? The extracted line would have knots and several endpoints. The output I needed is a n*2 array with the coordinates of each polyline between two knots or one knot and an endpoint separated by nans (the same way the coast file (shipped with the Mapping Toolbox) is stored).
Best regards,
Wolfgang
Wolfgang—Interesting problem. I have not done any work on such things, so I don’t have any algorithm ideas to share. The upcoming R2009a release of the Image Processing Toolbox has a new feature that might help, though. Watch for the release sometime next month.
Hi Steve - thanks for you reply. I am excited what kind of new features that will be.
Wolfgang—It won’t be a complete solution to the problem you posed, but I think it might help. I’ll post more details when the release goes live.
Hi Steve,
I want to understand the algorithm of extracting ordered pixel coordinates using 4 or 8-connected neighborhood. bwboundaries.m looks like a little bit advanced and compact for me to distinguish this part from others.
Is there any resource you can recommend?
Ahmet—If I remember correctly, bwboundaries is using something like the radial sweep algorithm described here.
Thanks Steve!
To all:
I want to save the vector line generated by bwtraceboundary having its coordinates indicated on the world file coordinates of an image.
Regards,
Ed
Ed—I assume you are having some kind of trouble? What have you tried, what was the result, and why was the result not satisfactory?
Hi Steve,
I need to find the minimum distance between two points in an image. For example, in the image on this page, it would be the distance between the two points on the neck. Because that is the smallest line that can be drawn across the image.
Is there a function to do this? if not, where can i get the help to develop such code?
LuckyGal—Can you refine your problem statement? The minimum distance between two foreground pixels in the thinned binary image above is 1, the distance between adjacent pixels. And there are many such pairs.
respected sir,
I’m Korean and a student studying bwboundaries function.
I have some question.
In BW image , how does the function(bwboundaries) find boundary pixel(coordinate). I want to know principle of
finding direction from current boundary pixel to next boundary pixel.
I think this principle is found at “boundaries.cpp”file and
“boundaries.h”file in Matlab toolbox.
but it is too hard for me to understand.
I guess fNextSearchDirectionLut(lookuptable) and fNextDirectionLut is important.
Assume that fConn=8(connectivity) and clockwise direction are given to us.
please tell me easily principle of finding direction.
I have many troubles studying C language code only.
please, send me answer through e-mail or here.
thank you, sir.
additionally, is there any thesis related to Radial Sweep
(Reply No.84)
Changmin—I have no idea. Probably.
Changmin—You might find this tutorial useful.
hi steve,
i am attempting to use the following code,
I=imread([’surface’,’.tif’])
level = graythresh(I);
BW = im2bw(I,level);
imshow(BW)
[x,y] = getpts(gcf);
x = round(x);
y = round(y);
however, whenever i try this, i get the following error:
Undefined function or method ‘graythresh’ for input arguments of type ‘uint8′
any ideas on how to overcome this? a similar error occurs with getpts(gcf)
thanks for your help!
KC—Sounds like you don’t have the Image Processing Toolbox installed.