renderscriptandroid-renderscript

Mirror symmetry of camera image using renderscript


I would like to take an input image and produce an output which is symmetrical about the central axis, i.e. reflected from right to left about the central vertical axis.

How might this be achieve using renderscript?

Example input image: enter image description here

Example output image: enter image description here


Solution

  • You can write a kernel that gets called for the left half of the image (via LaunchOptions), then do something like:

      int imageWidth;
      rs_allocation inputImage;
    
      <yourReturnType> RS_KERNEL mirror(<yourImageType> in, uint32_t x, uint32_t y){
          return rs_GetElementAt(inputImage, imageWidth - x, y);
      }
    

    You should be able to to direcetly overwrite your input image, since you only do reading to one side of the image and only do writing to the other side.