Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ij.*;
- import ij.process.*;
- import ij.plugin.filter.*;
- import ij.gui.NewImage;
- import ij.gui.*;
- import java.awt.Color;
- public class GrayToColor implements PlugInFilter{
- public void run(ImageProcessor ip){
- int w= ip.getWidth();
- int h= ip.getHeight();
- String title = "Same image with color changed";
- ColorChooser cc = new ColorChooser("couleur", Color.yellow, true);
- Color cRef = cc.getColor();
- if(cRef == null){
- IJ.error("Plugin Canceled");
- return;
- }
- int rRef = cRef.getRed();
- int gRef = cRef.getGreen();
- int bRef = cRef.getBlue();
- ImagePlus grayImage = NewImage.createRGBImage(title, w,h,1, NewImage.FILL_WHITE);
- ImageProcessor ipGrayImage = grayImage.getProcessor();
- int r,g,b;
- for(int y=0; y<h; y++ )
- {
- for(int x=0; x<w ; x++ )
- {
- r = (ip.getPixel(x,y)& 0xff0000) >>16;
- g = (ip.getPixel(x,y)& 0x00ff00) >>8;
- b= (ip.getPixel(x,y) & 0x0000ff);
- int[] rgb = {(r + rRef), (g + gRef), (b + bRef)};
- ipGrayImage.putPixel(x,y,rgb);
- }
- }
- grayImage.show();
- grayImage.updateAndDraw();
- }
- public int setup(String arg, ImagePlus imp){
- if (arg.equals("about")){
- IJ.showMessage("Gray to colored image");
- return DONE;
- }
- return DOES_8G;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement