Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import ij.*;
  2. import ij.process.*;
  3. import ij.plugin.filter.*;
  4. import ij.gui.NewImage;
  5. import ij.gui.*;
  6. import java.awt.Color;
  7.  
  8. public class GrayToColor implements PlugInFilter{
  9.  
  10. public void run(ImageProcessor ip){
  11.  
  12. int w= ip.getWidth();
  13. int h= ip.getHeight();
  14. String title = "Same image with color changed";
  15. ColorChooser cc = new ColorChooser("couleur", Color.yellow, true);
  16. Color cRef = cc.getColor();
  17.  
  18. if(cRef == null){
  19.  
  20. IJ.error("Plugin Canceled");
  21. return;
  22.  
  23. }
  24.  
  25. int rRef = cRef.getRed();
  26. int gRef = cRef.getGreen();
  27. int bRef = cRef.getBlue();
  28.  
  29. ImagePlus grayImage = NewImage.createRGBImage(title, w,h,1, NewImage.FILL_WHITE);
  30. ImageProcessor ipGrayImage = grayImage.getProcessor();
  31.  
  32. int r,g,b;
  33.  
  34. for(int y=0; y<h; y++ )
  35. {
  36. for(int x=0; x<w ; x++ )
  37. {
  38. r = (ip.getPixel(x,y)& 0xff0000) >>16;
  39. g = (ip.getPixel(x,y)& 0x00ff00) >>8;
  40. b= (ip.getPixel(x,y) & 0x0000ff);
  41.  
  42.  
  43. int[] rgb = {(r + rRef), (g + gRef), (b + bRef)};
  44. ipGrayImage.putPixel(x,y,rgb);
  45. }
  46. }
  47. grayImage.show();
  48. grayImage.updateAndDraw();
  49. }
  50.  
  51. public int setup(String arg, ImagePlus imp){
  52.  
  53. if (arg.equals("about")){
  54.  
  55. IJ.showMessage("Gray to colored image");
  56. return DONE;
  57.  
  58. }
  59.  
  60. return DOES_8G;
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement