如何在 Matlab 中将使用松散选项旋转的图像中的点转换为使用裁剪选项旋转的图像中的点?
How to convert a point in image imrotated with loose option to a point in image imrotated with crop option in Matlab?
如何找到图像 imrotated
与 loose 选项 Image 1 和图像 imrotated
之间的关系裁剪选项图片2?不需要旋转角度 -45° ...
I = imread('cameraman.tif');
Im1 = imrotate(I,-45); % bbox option sets to 'loose' by default
Im2 = imrotate(I,-45,'nearest','crop'); % bbox option sets to 'crop'
figure(1);
subplot(2,1,1), imagesc(Im1), axis image;
subplot(2,1,2), imagesc(Im2), axis image;
我的意思是,如果我从 Im1 中选择一个点 (x1,y1) 什么是 方程 它与 (x2,y2) 在 Im2 中的关系 ??我正在寻找 loose2crop()
方程式 ?
我找到了解决方案,请随时检查它的乐趣:)
I = imread('cameraman.tif');
Im1 = imrotate(I,-45); % Image imrotated with loose option
Im2 = imrotate(I,-45,'nearest','crop');% Image imrotated with crop option
% draw image 1 loose
figure(1);
subplot(2,1,1), imagesc(Im1), axis image;
drawnow;
%%Get a point
title('Select a point'); hold on;
[p1] = ginput;
plot (p1(1),p1(2),'k*');
drawnow;
% convert loose p1 to crop image
p2 = loose2crop(Im1,Im2,p1)
% draw Image 2 cropped
subplot(2,1,2), imagesc(Im2), axis image, hold on;
plot (p2(1),p2(2),'r*');
drawnow;
function p2 = loose2crop(Im1, Im2, p1)
[h1,w1] = size(Im1);
[h2,w2] = size(Im2);
shift_h = (h1 - h2)/2 ;
shift_w = (w1 - w2)/2 ;
p2(1) = p1(1) - shift_h ;
p2(2) = p1(2) - shift_w ;
如何找到图像 imrotated
与 loose 选项 Image 1 和图像 imrotated
之间的关系裁剪选项图片2?不需要旋转角度 -45° ...
I = imread('cameraman.tif');
Im1 = imrotate(I,-45); % bbox option sets to 'loose' by default
Im2 = imrotate(I,-45,'nearest','crop'); % bbox option sets to 'crop'
figure(1);
subplot(2,1,1), imagesc(Im1), axis image;
subplot(2,1,2), imagesc(Im2), axis image;
我的意思是,如果我从 Im1 中选择一个点 (x1,y1) 什么是 方程 它与 (x2,y2) 在 Im2 中的关系 ??我正在寻找 loose2crop()
方程式 ?
我找到了解决方案,请随时检查它的乐趣:)
I = imread('cameraman.tif');
Im1 = imrotate(I,-45); % Image imrotated with loose option
Im2 = imrotate(I,-45,'nearest','crop');% Image imrotated with crop option
% draw image 1 loose
figure(1);
subplot(2,1,1), imagesc(Im1), axis image;
drawnow;
%%Get a point
title('Select a point'); hold on;
[p1] = ginput;
plot (p1(1),p1(2),'k*');
drawnow;
% convert loose p1 to crop image
p2 = loose2crop(Im1,Im2,p1)
% draw Image 2 cropped
subplot(2,1,2), imagesc(Im2), axis image, hold on;
plot (p2(1),p2(2),'r*');
drawnow;
function p2 = loose2crop(Im1, Im2, p1)
[h1,w1] = size(Im1);
[h2,w2] = size(Im2);
shift_h = (h1 - h2)/2 ;
shift_w = (w1 - w2)/2 ;
p2(1) = p1(1) - shift_h ;
p2(2) = p1(2) - shift_w ;