Shift Individual Color Plane By Subpixel
Posted: 2017-07-13T10:36:04-07:00
Hello,
I'm attempting to use IM to perform a correction on an image where the green channel of a 1920x1080 RGB image is offset half a pixel in both the positive X and Y directions. My intention is to move the green channel back into alignment with the blue and red channels.
My current approach is to double the size of the image so that the correction becomes a integer number of pixels, separate each channel into a file, use page to shift the green channel with a transparent background, combine the images, and then use a point filter to scale back to the original size.
However, this is fairly inefficient because I do not really need the intermediate files. I was having trouble coming up with a command that does this without the need to write out the files. Also I'm interested if there is a method to avoid the resize and work directly with a floating point translation of the green channel.
Edit: I'm using version ImageMagick 7.0.2-10
I'm attempting to use IM to perform a correction on an image where the green channel of a 1920x1080 RGB image is offset half a pixel in both the positive X and Y directions. My intention is to move the green channel back into alignment with the blue and red channels.
My current approach is to double the size of the image so that the correction becomes a integer number of pixels, separate each channel into a file, use page to shift the green channel with a transparent background, combine the images, and then use a point filter to scale back to the original size.
Code: Select all
convert checker.bmp -resize 200% checker2.bmp
convert -page -1-1 checker2.bmp -channel G -separate -background none -flatten checker_shifted_green.bmp
convert checker2.bmp -channel R -separate checker_red.bmp
convert checker2.bmp -channel B -separate checker_blue.bmp
convert checker_red.bmp checker_shifted_green.bmp checker_blue.bmp -set colorspace RGB -combine -set colorspace sRGB checker_combined.bmp
convert checker_combined.bmp -filter Point -resize %50 checker_combined_smaller.bmp
Edit: I'm using version ImageMagick 7.0.2-10