Filter löschen
Filter löschen

Histogram within Minimum Bounding Box

2 Ansichten (letzte 30 Tage)
Hg
Hg am 11 Jul. 2015
Bearbeitet: Hg am 13 Jul. 2015
How do I calculate the histogram within a minimum bounding box, along the orientation of the rectangle? Let say I have the coordinates of the four corners.

Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Jul. 2015
Ignore my last answer since it doesn't look like you want "the histogram within a minimum bounding box" like you said first. The second part of your question looks like you really want the radon transform. To get the radon transform, look it up in the help. The radon transform is the sum of your image (the profile) as it's summed along a particular angle, which is what it sounds like you want.
I'm attaching a demo where I use the radon transform to rotate an image to align it with the raster lines.
  3 Kommentare
Image Analyst
Image Analyst am 13 Jul. 2015
It you have the coordinates of the box, like you said you did, then the angle is just atan2(deltaY/deltaX). With that angle, you can put it into the radon() function to get the sum of the shape along that direction.
Hg
Hg am 13 Jul. 2015
Bearbeitet: Hg am 13 Jul. 2015
I don't quite understand. For example, in the rotated image (last image), the black dot under the letter 'D' on the football has coordinate (195,255). How can I get the coordinate of the dot in the original image? I've tried imrotate() with the -angle but the size of the image changed.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 11 Jul. 2015
If you've gotten the vertices of the ROI, say using John D'Errico's excellent bounding object app, then you can simply use poly2mask to create a binary image and then call imhist():
[rows, columns, numberOfColorChannels] = size(grayImage);
rectMask = poly2mask(xVertices, yVertices, rows, columns);
[pixelCounts, grayLevels] = imhist(grayImage(rectMask));
grayImage(rectMask) gives a 1D list of only those pixels inside your ROI (the tilted rectangle). Of course you'll have some pixels in the black part of your binary image included along with the pixels inside the irregularly-shaped white blob because it's everything inside the rectangle, not just stuff inside the white blob.

Community Treasure Hunt

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

Start Hunting!

Translated by