Need help in pixel count!

Hi everybody! I'm struggling to get this one solved.
I have a binary image(640x480) full of 'Salt and Pepper' noise, and I need to count the pixels that are inside a imaginary square with dimensions 100x100, rotated 30º. The upper left pixel of the square (corner) has to be lying in the pixel (200,100) of the image.
I think the best way to solve this is to create a mask with the square rotated and then apply it to the image.
What would be the best way to get it done? I dont get how I guarantee that the upper left corner of the square would be in the pixel (200,300). I need to get a new image with the same size of the original with the square in the right position. Do you have any ideas to solve this?
Here's an image to show you what I mean. http://dl.dropbox.com/u/5272012/Untitled.png

Respuestas (2)

Sean de Wolski
Sean de Wolski el 30 de Mzo. de 2012

0 votos

Do you want the upper corner at 200,300 or the lefter corner at 200,300. Looking at the image I can't tell.
Either way, you could use the second output from max(bw(:)) on your mask image and sub2ind() to find row/col coordinates. This will be the index of the first maximizer it finds, guaranteed to be a corner and guaranteed to be 1 in an binary image. Whether it's the top corner or the left corner will depend on whether you transpose the mask first.

2 comentarios

Walter Roberson
Walter Roberson el 30 de Mzo. de 2012
"lefter" ?
Sean de Wolski
Sean de Wolski el 30 de Mzo. de 2012
you got the gist right? ;)
I guess I should apply the Maine-accent
that vertex is leftah than the uppah one!

Iniciar sesión para comentar.

Rui Trovisco
Rui Trovisco el 31 de Mzo. de 2012

0 votos

Solved! Thanks!

1 comentario

Image Analyst
Image Analyst el 31 de Mzo. de 2012
I'd guess it was via poly2mask(), thresholding, regionprops, then doing hist([measurements.Area], nBins). Once you have the corner coords, it's basically 4 key lines of code (more if you add comments, display images, print out results, etc.)

Iniciar sesión para comentar.

Productos

Etiquetas

Preguntada:

el 30 de Mzo. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by