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 comentarios

Adam
Adam el 21 de Ag. de 2019
Why do you have to use a nested for loop rather than just the standard flip functions?
column and row are constant scalars in that code so assigning to
transposedMatrix( column, row )
in a loop doesn't make sense. Maybe you mean j, i instead?
Jesse Schultz
Jesse Schultz el 21 de Ag. de 2019
It was asked to make a nested for loop, when I put j,i istead it rotated the image 90degrees, but it needs to be rotated 180. This is what ive been struggling with
Joel Handy
Joel Handy el 21 de Ag. de 2019
Well that invalidates my answer. Does the image need to be rotated or flipped. There is a difference.
Jesse Schultz
Jesse Schultz el 21 de Ag. de 2019
Editada: Jesse Schultz el 21 de Ag. de 2019
flipped both vertically and horizontally
Adam
Adam el 21 de Ag. de 2019
Well, a flip instruction would be more like exchanging position i with row - i and j with column - j

Iniciar sesión para comentar.

 Respuesta aceptada

Joel Handy
Joel Handy el 21 de Ag. de 2019
Editada: Joel Handy el 21 de Ag. de 2019

1 voto

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 comentarios

Jesse Schultz
Jesse Schultz el 21 de Ag. de 2019
I would do it like this, but its been asked if I can write it with nested for loops, so I can't use the flip function
Joel Handy
Joel Handy el 21 de Ag. de 2019
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 el 21 de Ag. de 2019
Thats exactly what I was doing wrong, thankyou!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing and Computer Vision en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Ag. de 2019

Comentada:

el 21 de Ag. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by