フィルターのクリア

Finding center of symmetry between zones in a image

11 ビュー (過去 30 日間)
Vivek
Vivek 2022 年 7 月 28 日
編集済み: Vivek 2022 年 8 月 2 日
I have and image such as below (I am pasting only a sketch here) where I want to calculate the center of symmetry and the displacement between the 2 marked zones in the image(Marked in Red and blue). Could anyone suggest a simple algorithm for this (Basic code sniippet would also help). (Please note the signal is symmetric to 180 degree rotation). [The idea is to calculate the center of symmetry between the red and blue zones]
  3 件のコメント
Vivek
Vivek 2022 年 7 月 28 日
No. The center of symmetry will be in the midddle of linesegment joiing the centroid in the sketch i have shown. But there could be images without a line segment as in the red zone. The region marked in red could be simliar to the blue zone , just thicker or thinner lets say.
Walter Roberson
Walter Roberson 2022 年 7 月 28 日
You have not given us any idea how far off the ideal the situation could get.
At the moment, with what you have shown us, and assuming the red and blue lines are not actually present in the images, just regionprops() asking for 'Centroid', sort by x coordinate, then take the middle of each consecutive line segment joining the now-sorted coordinates.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2022 年 7 月 28 日
Try this. The centroid of each blob is found and a vertical line is drawn there.
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = 'mO7aP.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = rgbImage(:, :, 1);
else
grayImage = rgbImage;
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 3, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Display histogram
subplot(2, 3, 2);
histogram(grayImage, 256);
grid on;
title('Histogram of Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Binarize the image to get a mask.
threshold = 242;
mask = grayImage < threshold;
% Display mask image.
subplot(2, 3, 3);
imshow(mask);
axis('on', 'image');
drawnow;
caption = sprintf('Mask using a threshold of %.1f', threshold);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Fill the blobs
mask = imfill(mask, 'holes');
% Take 5 largest blobs.
mask = bwareafilt(mask, 5);
subplot(2, 3, 4);
imshow(mask);
axis('on', 'image');
drawnow;
title('Final Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage, numberOfBlobs] = bwlabel(mask, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
subplot(2, 3, 5);
imshow(coloredLabelsImage);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'Area', 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
caption = sprintf('%d Individual Blobs', numberOfBlobs);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Get the areas
allAreas = [blobMeasurements.Area];
% Get the centroids
xy = vertcat(blobMeasurements.Centroid);
xCentroids = xy(:, 1);
yCentroids = xy(:, 2);
% Draw lines over centroids.
hold on;
for k = 1 : numberOfBlobs
xline(xCentroids(k), 'LineWidth', 2, 'Color', 'k');
plot(xCentroids(k), yCentroids(k), 'y+', 'LineWidth', 2, 'MarkerSize', 30);
end
hold off;
% Show size of Areas.
subplot(2, 3, 6);
bar(allAreas);
grid on;
xlabel('Area in Pixels', 'FontSize', fontSize, 'Interpreter', 'None');
ylabel('Blob Index', 'FontSize', fontSize, 'Interpreter', 'None');
title('Blob Areas', 'FontSize', fontSize, 'Interpreter', 'None');
  11 件のコメント
Vivek
Vivek 2022 年 7 月 29 日
編集済み: Vivek 2022 年 7 月 29 日
.Thanks you for your explnations.Just to explain what I am trying to caluclate. Lets take the example image below.The image in the left has 2 regions selected and the image in the right has 2 regions selected.
The error I want to calculate is the planar distance from the center of gravity of the 2 boxes in the left image to the center of the gravity of the 2 boxes in the right image. In this case I am trying to the centerline of each structure along both the X . Pleas omit the 6 in the right image.
Thats why I was asking if we take 1D prfile of the regions (original and fliiped) (Something like below) specified and a correlation we can determine the placement error of the 2 structures .(Subtraction should give us the pixel difference)
Image Analyst
Image Analyst 2022 年 7 月 29 日
You can crop the image so that the new image starts at the top of the box and the last line of the image is the last line of the box. Then find the centroids as I showed you. To find the center of the two boxes (#'s 2 and 5) in the left image you can do
% Find "center of gravity of the 2 boxes in the left image"
xctr = (xCentroid(2) + xCentroid(5)) / 2;
To do the same thing for the right image for blobs 3 and 4:
xctr = (xCentroid(3) + xCentroid(4)) / 2;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by