Error in flipping

조회 수: 5 (최근 30일)
Cecilia Adriana
Cecilia Adriana 2012년 1월 11일
Hi, all
I have a problem in flipping an image. I use flipud function from Matlab, but it keeps error
img = imread('peppers.png'); F = flipud(img); imshow(img); title('Image'); figure, imshow(F); title('Flip Vertical');
The error message was
??? Error using ==> flipud at 19 X must be a 2-D matrix.
Error in ==> Untitled8 at 4 F = flipud(img);
Can anyone tell me how to solve this? Thanks

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 11일
Hi,
It seem you use flipud command for 3D matrix.
Peppers.png was 3D uint8 matrix.
'??? Error using ==> flipud at 19 X must be a 2-D matrix' - means flipud takes 2D matrix.
So, you can use my function to perform 3D flipping :
function J = flipping(I)
[row col dim] = size(I);
J = zeros(row,col,dim);
mirror = floor(row/2);
for x = 1 : row-1
for y = 1 : col-1
J(x,y,:) = I((2*mirror)-x,y,:);
end
end
And then you can call it by :
I = imread('peppers.png');
J = flipping(I);
imshow(uint8(J));
And see the result below :
%
  댓글 수: 1
Cecilia Adriana
Cecilia Adriana 2012년 1월 11일
Thanks, sir!
It works

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 1월 11일
F = img(end:-1:1,:,:);
  댓글 수: 1
Cecilia Adriana
Cecilia Adriana 2012년 1월 11일
It works too,
thanks anyway!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by