The problem about mirror image
2 views (last 30 days)
Show older comments
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 Comments
Adam
on 12 Sep 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.
Accepted Answer
Image Analyst
on 12 Sep 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]);
0 Comments
More Answers (0)
See Also
Categories
Find more on 图像算术 in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!