Here is an example of a function I wrote to change the color palette used in an image. The above example comes from a black and white original, although color images can also be used. The function first converts the image to grayscale in order to have levels of color intensity between 0-255. Using a new color palette with 256 color levels, the gray levels are replaced with a rgb (red, blue, green) vector from the new palette. The results can be very strange...
The package biOps is required for reading and writing the .jpeg files.
the function...
Created by Pretty R at inside-R.org
The original image (from Wikimedia Commons):
the script used to create the modified image using the image2pal() function...
require(biOps) x<-readJpeg("Uss-akron-manhattan.jpg") cpal<-colorRampPalette(c("black","black","blue","red","yellow")) x_pal <- image2pal(x, cpal) writeJpeg("Uss-akron-manhattan_w_pal.jpg", x_pal)
No comments:
Post a Comment