Python function to mirror image vertically from R to L

I am trying to write a python function to flip the right half of the image in the left half. So far I have this code, but it works the other way around (it reflects from L to R). I know that this should be a few simple changes, but now I now have a block. Any help was appreciated.

def mirrorVertical(source): mirrorPoint = getWidth(source) / 2 width = getWidth(source) for y in range(0,getHeight(source)): for x in range(0,mirrorPoint): leftPixel = getPixel(source,x,y) rightPixel = getPixel(source,width - x - 1,y) color = getColor(leftPixel) setColor(rightPixel,color) 
+4
source share
3 answers
  color = getColor(rightPixel) setColor(leftPixel,color) 
0
source

It seems that you are iterating from the top left corner to the middle, instead of the right corner to the middle. Perhaps you want to try the range (getWidth (), mirrorPoint) for x and leave y the same.

0
source

Before changing the rightPixel color, you must save this color somewhere to set it to leftPixel .

Sort of

 color_left = getColor(leftPixel) color_right = getColor(rightPixel) setColor(leftPixel, color_right) setColor(rightPixel, color_left) 

gotta do the trick.

0
source

Source: https://habr.com/ru/post/1438745/


All Articles