Histogram within Minimum Bounding Box
古いコメントを表示
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.

採用された回答
その他の回答 (1 件)
Image Analyst
2015 年 7 月 11 日
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.
カテゴリ
ヘルプ センター および File Exchange で Region and Image Properties についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
