The problem about mirror image

Hello, everyone. I read a code about mirror image from my reference booka hour ago and debug it, though it runs well, but there is something troubles me a lot.
if true
I=imread('C:\Users\yanghang\Pictures\0.jpg');
subplot(1,2,1);
imshow(I);
I=double(I);
h=size(I);
I_fliplr(1:h(1),1:h(2),1:h(3))=I(1:h(1),h(2):-1:1,1:h(3));%水平镜像
I1=uint8(I_fliplr);
subplot(1,2,2);
imshow(I1);
end
Firstly, Why there exists the format change? 'I' is uint8 before, then double then uint8 again. I want to express mirror in another way, so replace the
if true
% I_fliplr(1:h(1),1:h(2),1:h(3))=I(1:h(1),h(2):-1:1,1:h(3));
imrotate(I,-180);
set(gca,'###','reverse')% whether the second part should be the image?
end

3 Commenti

Adam
Adam il 11 Set 2017
Modificato: Adam il 11 Set 2017
set(gca,'###','reverse')
needs 'XDir' or 'YDir' (or 'ZDir', but not for an image) as the second argument if you want to flip the axis.
To flip the image itself you would do what the code does (well, I haven't checked if it is correct, but applying the flip to the data itself rather than the graphics).
I never like to spend too long looking at code that people post from some unknown source asking why it does what it does though because there is no guarantee that random code is in any way sensible so trying to explain its logic is sometimes just a pointless task! If you are following an example from Matlab help or some other obviously reputable source it is useful to include that to at least give us an idea the code is not just bad code from someone who doesn't know what they are doing.
Y
Y il 11 Set 2017
Thanks a lot. Could U recommend some reliable sources ? I only know Matlab help. Thanks again.
Adam
Adam il 12 Set 2017
The Matlab Help is by far the best source and most of the time the only one you need, but a google search will often lead you to Matlab Answers threads also.

Accedi per commentare.

 Risposta accettata

Image Analyst
Image Analyst il 12 Set 2017
You don't need all that complicated stuff with indexes and casting to double and uint8. Sometime a few versions ago, they made fliplr() smart enough to handle color images. So simply do:
rgbImage = imread('C:\Users\yanghang\Pictures\0.jpg');
subplot(1,2,1);
imshow(rgbImage);
title('Original Image', 'FontSize', 30);
flippedImage = fliplr(rgbImage);
subplot(1,2,2);
imshow(flippedImage);
title('Mirror Image', 'FontSize', 30);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);

Più risposte (0)

Categorie

Scopri di più su 图像 in Centro assistenza e File Exchange

Richiesto:

Y
Y
il 11 Set 2017

Commentato:

il 12 Set 2017

Community Treasure Hunt

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

Start Hunting!