Umkehren werde ich mit einem Bild erklären, so dass Sie ein besseres Verständnis gewinnen können, wie unten zu sehen:Probleme mit einem gedrehtes Bild in MATLAB
Mit dem obigen Ergebnis erscheint alles als normal. Ich habe ein Bild und ich versuche, dieses Bild mit imrotate
zu drehen. In diesem Fall verwende ich eine Drehung um 45 Grad gegen den Uhrzeigersinn. Wenn ich jedoch versuche, die Rotation umzukehren (mein Ziel ist es, die normale Position des Bildes ohne Rotation zu erhalten), wird alles merkwürdig - besonders bei der Bildauflösung. Die Bildauflösung nimmt ab und die Größe des Bildes ändert sich aufgrund des Rauschens in diesem Bild, wie Sie in der obigen Abbildung sehen können.
Zusätzliche Informationen
Echtbildinformationen:
- Breite: 512
- Höhe: 384
Crop Bildinformationen:
- Breite: 513
- Höhe: 385
Meine Frage ist folgende - Wie erhalte ich ein sauberes und schönes Bild wie das Originalbild?
Ich habe den Code, den ich unten schrieb:
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('------------------------');
Vielen Dank, diese Methode funktioniert perfekt, aber, es gibt immer noch ein kleines Problem über die Größe des Bildes, sie ändern sich auch, das ist mein letztes Ergebnis über die Größe: Real Image Information: Breite: 512 Höhe: 384 -----> Return Image Information: Breite: 513 Höhe: 385 ------------------------ >> und wenn ich es versuche um zu vergrößern, gibt es ein schwarzes zusätzliches Pixel auf jeder Seite des Bildes, wie man dieses Pixel eliminiert und die richtige Größe des Bildes wie echtes Bild erhält –
Die Größe, die Sie nicht ändern können, weil das Bild gerade in der Dimension ist ... Das ist das Problem beim automatischen Zuschneiden. Diese Größenunterschiede können vermieden werden, indem die Zeilen und Spalten ungerade sind. Du kannst nichts anderes tun. – rayryeng
Haben Sie einen anderen Code zum automatischen Beschneiden für ein besseres Ergebnis? –