【发布时间】:2016-04-16 15:25:27
【问题描述】:
我将用一张图片来解释,以便您更好地理解,如下所示:
有了上述结果,一切正常。我有一些图像,我尝试用imrotate 旋转这个图像。在这种情况下,我使用 45 度逆时针旋转。但是,当我尝试反向旋转时(我的目的是在不旋转的情况下获得图像的正常位置),一切都变得奇怪 - 特别是在图像分辨率下。如上图所示,由于该图片中有很多噪点,图像分辨率会降低,并且图像的大小会发生变化。
其他信息
-
真实图像信息:
- 宽度:512
- 身高:384
-
裁剪图像信息:
- 宽度:513
- 身高:385
我的问题如下 - 如何获得像原始图像一样干净漂亮的图像?
我的代码如下所示:
clc;
close all; % Close all figure windows except those created by imtool.
imtool close all;
clearvars; % Get rid of variables from prior run of this m-file.
workspace; % Make sure the workspace panel is showing.
Rotation=45;
%Read the image
imagepad = imread('peppers.png');
%% Image Source Information
info1=size(imagepad);
fprintf('Real Image Information : \n'); % Message sent to command window.
fprintf(' Width : %d\n',info1(2)); % Message sent to command window.
fprintf(' Height : %d\n',info1(1)); % Message sent to command window.
fprintf('------------------------');
%%Try Rotate 45 degree
imRotate = imrotate(imagepad,Rotation);
%%
figure;
subplot(121);
imshow(imagepad);
caption = sprintf('Real Image');
title(caption, 'FontSize', 13);
subplot(122);
imshow(imRotate);
caption = sprintf('Rotate 45 degree result');
title(caption, 'FontSize', 13);
%%try to return the image position
imReturn = imrotate(imRotate,-Rotation);
%%Try to return the size of image
%% find pixel
%im = imread('im.png'); %# load image
[y,x] = find(all(imReturn>0, 3)); %# find black pixels
position = [x,y]; %# display them
[x1]=min(position);
[x2]=max(position);
%%Normal Size
Im2 = imcrop(imReturn,[x1(1) x1(2) (x2(1)-x1(1)) (x2(2)-x1(2))]);
figure, imshow(Im2);
caption = sprintf('Last Result image size');
title(caption, 'FontSize', 13);
%%
figure;
subplot(221);
imshow(imagepad);
caption = sprintf('Real Image');
title(caption, 'FontSize', 13);
subplot(222);
imshow(imRotate);
caption = sprintf('Rotate 45 degree result');
title(caption, 'FontSize', 13);
subplot(223);
imshow(imReturn);
caption = sprintf('Inverse Rotate 45 degree result');
title(caption, 'FontSize', 13);
subplot(224);
imshow(Im2);
caption = sprintf('Crop result');
title(caption, 'FontSize', 13);
%%Different Resolution
subplot(121);
imshow(imagepad);
caption = sprintf('Real Image');
title(caption, 'FontSize', 13);
subplot(122);
imshow(Im2);
caption = sprintf('Crop result');
title(caption, 'FontSize', 13);
%% Image Source Information
info2=size(Im2);
fprintf('Return Image Information : \n'); % Message sent to command window.
fprintf(' Width : %d\n',info2(2)); % Message sent to command window.
fprintf(' Height : %d\n',info2(1)); % Message sent to command window.
fprintf('------------------------');
【问题讨论】:
标签: image matlab image-processing rotation