Evaluate the centre of gravity in dependence of horizontal position for each interfernece fringe of image
3 views (last 30 days)
Show older comments
MUHAMMAD ANUS
on 18 Jun 2021
Commented: Image Analyst
on 22 Jun 2021
% Calculating the Centre of Gravity
grayImage = img;
binaryImage = true(size(grayImage));
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, grayImage, 'WeightedCentroid')
centerOfMass = measurements.WeightedCentroid
hold on;
plot(centerOfMass(1), centerOfMass(2), 'r*', 'LineWidth', 2, 'MarkerSize', 16);
Using this code I am able to find the Centre points but if I need to crop my image and the dimensions are changed there are bugs which I don't understand or able to correct.
What I am trying to do is to select one line / row from y-axis where I think is the most noticeable change is and finding the centre of gravity for that particular line. My image has a 1000*1000 pixel and along x-axis I want to see all the 1000 pixels.
For the solution, I think I need to crop the image after selecting one line and take the centre of gravity any one can explain how to do that?
% Calculate Sum Or Mean
A = sum(img,2);
B = sum(img,1);
% I get a matrix A =1000*1 and B= 1*1000
%%
(C,D)= size(img);
figure(5)
[X Y] = size(img);
xcentre = img(:,X./2);
figure(5);
plot(xcentre);
6 Comments
Bjorn Gustavsson
on 22 Jun 2021
@MUHAMMAD ANUS: The definition of "center of gravity" is:
This can be directly adapted to 2-D images to get a corresponding "center of intensity". Sure isolate individual interference fringes and set the remaining image to zero, after proper background reduction. Then the above equation should be simple enough to implement, most likely component-by-component.
Accepted Answer
Image Analyst
on 22 Jun 2021
Try extracting the one line of the image you want, then doing a weighted ratio
[rows, columns, numColorChannels] = size(croppedImage)
oneLine = croppedImage(73, :); % Get all pixel values of line 73 in the cropped image.
x = 1 : columns;
numerator = sum(oneLine .* x)
denominator = sum(oneLine)
weightedXCentroid = numerator / denominator
2 Comments
Image Analyst
on 22 Jun 2021
Correct. You can do
plot(x, oneLine, 'b-', 'LineWidth', 2);
xline(weightedXCentroid, 'Color', 'r');
or if you have an old version of MATLAB that does not have xline() yet, you can put hold on and do
hold on;
plot([weightedXCentroid, weightedXCentroid], ylim, 'r-', 'LineWidth', 2);
hold off;
The weighted centroid is of course intensity weighted. You can see right there in the numerator and denominator that oneLine (the vector of intensities) in in them. I don't know what your fringes look like changed and unchanged so I don't know if weighted centroid of a particular line is the right thing to do or not -- I just trusted you on that. You can also get the 2-D weighted centroid like you have done but you need a gray scale image, not a pseudocolored image or not a pseudocolored image converted to gray scale with rgb2gray(). That would not make sense.
I'm sure there is probably open source fringe analysis software out there somewhere, like maybe from the College of Optical Sciences at the University of Arizona, or from U.Rochester's Institute of Optics, or maybe MATLAB's File Exchange or the similar plug-in web site for ImageJ.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!