필터 지우기
필터 지우기

How to draw a circle on existed circle ? How to calculate the image shift in pixels from its center?

조회 수: 1 (최근 30일)
Can we draw two circles, one inside and the other outside of the above link circle.

채택된 답변

Image Analyst
Image Analyst 2013년 1월 1일
You can use bwboundaries if all you want to do is draws outlines of the boundaries in the overlay above the original image:
format longg;
format compact;
clc; % Clear command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 25;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Naresh\Documents\Temporary';
baseFileName = 'imfill.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, '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
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage)
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis square;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Create a binary image.
binaryImage = grayImage < 128;
subplot(2, 2, 2);
imshow(binaryImage);
axis square;
title('Binary Image', 'FontSize', fontSize);
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original grayscale image using the coordinates returned by bwboundaries.
% Display the original gray scale image.
subplot(2, 2, 3);
imshow(grayImage, []);
title('Original Grayscale Image with Outlines from bwboundaries()', 'FontSize', fontSize);
axis square;
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r-', 'LineWidth', 3);
end
hold off;
  댓글 수: 2
Naresh Naik
Naresh Naik 2013년 1월 2일
편집: Naresh Naik 2013년 1월 2일
The center of the above image is at 211 X 251 (size(IMAGE)/2)).
Let us assume if that same image center is shifted at the location 282 X 169.
Now assume we don't know this location (i.e., 282 X 169 ).
My question is how to find out the center of the the circle which is shifted (from 211 X 251 ).
Image Analyst
Image Analyst 2013년 1월 2일
You wanted to use ginput(), so you call that and have the user click at the center. If the user clicked at the right place, ginput will return y = 282, and x = 169.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by