moving the center of an image from point to another?
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi All
i have this image
i want to moving it to the center of the whole figure , how this can be done in matlab i.e how can i raise this image to the center of the whole figure.
for example the first center point coordinates is 160 173 and the second center point coordinates is 160 121
how can i moving the center from first point to the second point?
i tried this code
y=imread('.......bmp');
[r c]=size(y);
for i=0:1:r
for j=1:1:c
y(i,j)=y(i,j+50);
end
end
imshow(y);
but the result was this error:
??? Attempted to access y(0,52); index must be a positive integer or logical.
any help? my regards
댓글 수: 0
채택된 답변
Image Analyst
2012년 1월 29일
Copy and paste this:
% Demo to shift a region in a binary image.
% By ImageAnalyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
grayImage = peaks(200);
imshow(grayImage, []);
subplot(2,2,1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
axis on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% imtool(z)
binaryImage = grayImage > 5;
subplot(2,2,2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
axis on;
% Find the centroid of that binary region
measurements = regionprops(binaryImage, 'Centroid')
[rows columns] = size(binaryImage);
rowsToShift = round(rows/2- measurements.Centroid(2))
columnsToShift = round(columns/2 - measurements.Centroid(1))
% Call circshift to move region to the center.
shiftedImage = circshift(binaryImage, [rowsToShift columnsToShift]);
subplot(2,2,3);
imshow(shiftedImage, []);
title('Shifted Binary Image', 'FontSize', fontSize);
axis on;
댓글 수: 0
추가 답변 (2개)
Image Analyst
2012년 1월 29일
Is zero a positive integer? No. Indexing starts at 1 in MATLAB. Anyway, that won't move it. That's more like a copy and paste rather than a cut and paste. Try circshift
out = circshift(in, [-50, 0]);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!