필터 지우기
필터 지우기

How to flip my image

조회 수: 115 (최근 30일)
Jesse Schultz
Jesse Schultz 2019년 8월 21일
댓글: Jesse Schultz 2019년 8월 21일
I have an image that I must flip using a nested for loop to flip the image vertically and horizontally, I have written a code that I think works but there is something wrong with it that it isn't. What have I done wrong?
%make 2d arrays values
imageData=imread('image.png');
[row, column] =size(imageData)
newImage=[]
%Use nested loops to change image mirrored
for i=[row:-1:1];
for j=[column:-1:1];
transposedMatrix(column, row) = imageData(i,j);
transposedMatrix
end
end
imshow(transposedMatrix)
  댓글 수: 5
Jesse Schultz
Jesse Schultz 2019년 8월 21일
편집: Jesse Schultz 2019년 8월 21일
flipped both vertically and horizontally
Adam
Adam 2019년 8월 21일
Well, a flip instruction would be more like exchanging position i with row - i and j with column - j

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

채택된 답변

Joel Handy
Joel Handy 2019년 8월 21일
편집: Joel Handy 2019년 8월 21일
The are a few problems with your code. First, if you want the image, you dont want to transpose. That will flip and rotate, As adam has pointed out, column and row, you arent actuall transposing anyway. A better and correct way to transpose is to use permute.
imageData=imread('image.png');
newImage = permute(imageData, [2 1 3]);
imshow(newImage);
To actually flip, you should be able to use the flip function
imageData=imread('image.png');
newImage = flip(imageData,1);
newImage = flip(newImage,2);
imshow(newImage);
  댓글 수: 3
Joel Handy
Joel Handy 2019년 8월 21일
I that case . . .
%make 2d arrays values
imageData=imread('image.png');
[row, column] = size(imageData);
%Use nested loops to change image mirrored
for i=[1:row]
for j=[1:column]
newImage((row-i)+1, (column-j)+1) = imageData(i,j);
end
end
imshow(newImage)
You dont want to transpose rows and colums, you want to flip the the indexes within rows and columns.
Jesse Schultz
Jesse Schultz 2019년 8월 21일
Thats exactly what I was doing wrong, thankyou!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by