Reputation: 193
I'm making a project where I need to mirror an image vertically. The image is read by a function and then set into an array pixel by pixel, to move through this array I am using array[idy*w + idx]
(w being the width of the matrix or image in my case) now, since this will run concurrently I only need to find the opposite pixel so that I can assign it.
I mean something like this:
array[idy*w + idx] = array[opposite pixel];
array[opposite pixel] = array[idy*w + idx];
The problem is I can't find the proper way to do it.
Any answer would be highly appreciated.
I have tried doing the following but it doesn't work array[idy*w + (w - (idx + 1))]
Upvotes: 1
Views: 187
Reputation: 193
This is what worked for me in the end:
outputImage[idy*w + idx] = inputImage[idy*w + (w - idx - 1)];
Upvotes: 1
Reputation: 3352
This should work
pixel = array[idy*w + idx];
pixel_mirror = array[idy * (w + 1) - idx - 1];
array[idy*w + idx] = pixel_mirror;
array[idy * (w + 1) - idx - 1] = pixel
Upvotes: 0