Find the barycenter of luminance in an image
조회 수: 6 (최근 30일)
이전 댓글 표시
I need to find the weighted center of luminosity of barycenter in an image. (the weighted L center in Lab a b)
댓글 수: 2
채택된 답변
Image Analyst
2015년 10월 29일
편집: Image Analyst
2015년 10월 29일
Since R2008a (or maybe b) regionprops has had a "WeightedCentroid" property that you can ask for. So pass in the L channel and ask for that if you want the centroid weighted by the L value.
If you want it weighted by the distance, that's the inertia or moment. See https://en.wikipedia.org/wiki/Image_moment I don't think there's anything built in for that but you can ask for the PixelList which is the location of every pixel in the blob and you can easily calculate it yourself.
댓글 수: 6
Walter Roberson
2015년 10월 30일
No, L is not the label matrix here. L is the luminance channel, in accordance with IA's earlier "So pass in the L channel and ask for that if you want the centroid weighted by the L value."
A = imread('figure2.jpg');
LAB = rgb2lab(A);
L = LAB(:,:,1);
imageprops = regionprops(L, 'WeightedCentroid');
result = imageprops.WeightedCentroid;
If you want the "top half" then pass in the top half,
imageprops = regionprops(L(1:end/2,:), 'WeightedCentroid');
upperCent = imageprops.WeightedCentroid;
imageprops = regionprops(L(ceil(end/2):end,:), 'WeightedCentroid');
lowerCent = imageprops.WeightedCentroid;
추가 답변 (1개)
Image Analyst
2015년 10월 30일
David:
I wrote a demo for you to compute the first 5x5 central spatial moments, as given by the Wikipedia page https://en.wikipedia.org/wiki/Image_moment. See attached m-file. The key code is this:
% Sum up the powers of the gray levels, weighted by the distance from the centroids.
% Ref: https://en.wikipedia.org/wiki/Image_moment
highestMomentNumber = 5;
mu = zeros(highestMomentNumber, highestMomentNumber); % Allocate up to 5 moment (probably way overkill).
for q = 1 : size(mu, 2) % in the column, x direction.
for p = 1 : size(mu, 1) % in the row, y direction
for location = 1 : length(allX)
% For every pixel in this blob....
% Sum up for moment "mu sub pq" - i.e. the pqth moment.
thisGrayLevel = grayImage(allY(location), allX(location));
mu(p, q) = mu(p, q) + ...
(allX(location) - xCenter).^q * ...
(allY(location) - yCenter).^p * ...
double(thisGrayLevel);
end
end
end
See file for a complete demo.
댓글 수: 6
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!