image flipping without built in commands
Mostrar comentarios más antiguos
Hey everyone, I am trying to horizontally flip an image using arrays only. What I tried to do with this code was to go through every row in the original image and assign the values of every pixel in a row of the original image to a pixel in the processed image with the same row but reversed order. (meaning the value of the pixel in the first row the first column of the original image would be assigned to the pixel in the first row the last column of the processed image)
original_img=imread('someimg.jpg');
[row,col,layers] = size(original_img);
processed_img = zeros(row,col,layers);
processed_img(1:row,col:-1:1,:) = original_img(1:row,1:col,:);
The problem is that the algorithm seems to work for some pixels in the image but most of the processed image is still white (since it was initially an array of zeros). I couldn't get my head around the reason why this algorithm does not work. I know there are built-in functions to flip images but I am trying to do it by using array properties. Thanks a lot for your help.
Respuesta aceptada
Más respuestas (2)
James Tursa
el 22 de Jul. de 2016
Did you mean this?
newcat(1:row,1:col,:) = cat(row:-1:1,1:col,:);
Or this?
newcat(1:row,1:col,:) = cat(1:row,col:-1:1,:);
3 comentarios
Johann Sebastian Bach
el 22 de Jul. de 2016
James Tursa
el 22 de Jul. de 2016
Can you elaborate on "doesn't work?" What result are you expecting?
Johann Sebastian Bach
el 23 de Jul. de 2016
Image Analyst
el 23 de Jul. de 2016
0 votos
You should never use variables that are also built in functions. And you not only did it once, but twice. Don't use cat and dim as variables because those are built in functions.
What do you mean by "flip"? Flip vertically or horizontally or both? And why can't you use built-in functions? Are you asking us to do your homework for you?
1 comentario
Johann Sebastian Bach
el 23 de Jul. de 2016
Editada: Johann Sebastian Bach
el 23 de Jul. de 2016
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!