Ask Your Question
0

Resampling grid to remove noise before extracting chain code

asked 2016-03-20 21:32:14 -0600

bob409 gravatar image

updated 2016-03-21 09:17:07 -0600

In theory, as chain code is very sensitive to noise we should:

  • Superimpose a sampling grid
  • Resample to some fixed number of points

I have seen this approach many places but not an implementation anywhere. Or can we implement it using opencv?

image description

For example I have this image, I apply Canny edge detection. Then how do I make it become as follows:

image description

I do not even know how to place grid on the image and obtain the boundary vertices.

I have tried this using the suggestion of Tetragramm:

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-03-20 23:14:10 -0600

Tetragramm gravatar image

Try doing a resize down and then up again. The up direction should be INTER_NEAREST. This forces everything into a coarser grid. Then you threshold to remove grid cells that only barely had anything in them, and there you are. A downsampled grid. Apply your normal chain code generation to that, and all is well.

edit flag offensive delete link more

Comments

Thanks a lot for your advice. I will try to implement it. I did not understand how to "threshold to remove grid cells that only barely had anything in them". How to do it, do you have any idea?

bob409 gravatar imagebob409 ( 2016-03-21 01:11:34 -0600 )edit

I have tried implementing it. I am not getting the required result.

bob409 gravatar imagebob409 ( 2016-03-21 04:23:30 -0600 )edit

You're operating on a binary image, right? You after you downsample and then upsample again you need to run the threshold function to return it to a binary state.

Also, how far are you downsampling? The image you show looks to be about 5x5 to 1, so you should be using a scale factor of 0.2

Tetragramm gravatar imageTetragramm ( 2016-03-21 06:55:24 -0600 )edit

I have used the following code:

int main() { Mat img = imread("resampling.png", 0);

Size imgSize = img.size();

Size downSize = Size(img.size().width / 2, img.size().height / 2);
Canny(img, img, 100, 100 * 2, 3, false);


imshow("Original", img);
resize(img, img,downSize, 0, 0, INTER_AREA);

imshow("down", img);
resize(img, img, imgSize, 0, 0, INTER_NEAREST);

imshow("beforeThreshold", img);
threshold(img, img,130, 130 * 3, THRESH_BINARY);

imshow("Original1", img);

waitKey(0);

}

I have uploaded a picture of what I have tried above.

bob409 gravatar imagebob409 ( 2016-03-21 07:41:23 -0600 )edit

Oh wow, ok, I did mis-understand what you're doing.

So typically you would downsample before you do the canny edge detection. But your image is already squared off. So it won't do much of anything. Your chain code should already be evened out, only 30 or 31 points. What this method is supposed to do is reduce the number of points because of things like curves and whatnot.

So you can downsample far enough to lose features, but it will be very far. It would have to be smaller than 9x10 pixels.

Tetragramm gravatar imageTetragramm ( 2016-03-21 17:38:53 -0600 )edit

Do u know how to extract chain code from a shape so that it is scale invariant?

bob409 gravatar imagebob409 ( 2016-03-21 20:40:59 -0600 )edit

No idea, but I found this: http://www.cis.hut.fi/research/IA/pap...

Tetragramm gravatar imageTetragramm ( 2016-03-21 21:23:33 -0600 )edit

Thanks for helping me..

bob409 gravatar imagebob409 ( 2016-03-21 21:51:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-20 21:32:14 -0600

Seen: 719 times

Last updated: Mar 21 '16