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?
回答(2 个)
Sean de Wolski
2012-3-30
0 个投票
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 个评论
Walter Roberson
2012-3-30
"lefter" ?
Sean de Wolski
2012-3-30
you got the gist right? ;)
I guess I should apply the Maine-accent
that vertex is leftah than the uppah one!
Rui Trovisco
2012-3-31
0 个投票
1 个评论
Image Analyst
2012-3-31
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.)
类别
在 帮助中心 和 File Exchange 中查找有关 Discrete Fourier and Cosine Transforms 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!