问题
I work in my project on the problem of writer recognition from handwritten Arabic documents.
to identify the writer, I used a database image, My problem is how to extract features from these images. I'm new in matlab and I do not have much knowledge in image processing.
please help me, I need to extract the contour from image and then encode it using freeman chain codes.
The following link contains freeman code in matlab but I do not know how to use it.
I welcome your suggestion and thank you in advance
回答1:
You can use the imcontour
function.
For instance, if you load this sample image
Img = imread('test.png');
You can get the contour with the command:
C = imcontour(Img, 1);
Then you can use the freeman function you cite with C as the first input.
回答2:
Another example could be to use bwperim. This essentially takes a look at all of the distinct binary objects in an image and extracts the perimeter of each object. This only works for objects that are white, and so using @Crazy rat's example, we can thus do:
im = ~im2bw(imread('http://i.stack.imgur.com/p9BZl.png'));
out = ~bwperim(im);
The above will read in the image and convert it into binary / logical
. Next, we need to invert the image so that the object / text is white while the background is black. After, call bwperim
so that you extract the perimeter of the objects, and then to convert back so that the object text is black, we re-invert.
The output I get is:
The distinct advantage with bwperim
over imcontour
is that bwperim
provides the actual output image whereas imcontour
only draws a figure for you. You can certainly extract the image data from the figure, like using the h = gcf; out = h.cdata;
idiom, but this will include some of the figure background in the result. I suspect you would like the actual raw image instead, and so I would recommend using bwperim
.
How do we use this with the Freeman code you linked?
If you look at the source code, it takes in two inputs:
b
, which is aN x 2
matrix of coordinates that determine the boundary of the shape you want to encodeunwrap
- An optional parameter
If you want to use the function that you have linked us to, simply extract the row and column coordinates of those pixels that are along the boundary of your image. As such, this is another limitation of imcontour
, as you won't be able to determine these locations without the raw contour image itself. Therefore, all you really have to do is:
[y,x] = find(out == 0);
cc = chaincode([y x]);
来源:https://stackoverflow.com/questions/28367220/how-to-extract-contour-using-freeman-chain-code-using-matlab