Hi Amol,
I don't know imagej that much.
But I am doing the same thing with java imaging classes.
See the below modified code,It is working correctly.
Do same for other extension files.
BufferedImage image = ImageIO.read(new File("D:\\dicom\\About.jpg"));
ImagePlus imagePlus = new ImagePlus();
imagePlus.setImage(image);
ImageProcessor imageProcessor = imagePlus.getProcessor();
//imageProcessor.autoThreshold();
ImageProcessor ip2 = imagePlus.getProcessor();
double image_width = ip2.getWidth();
double image_height = ip2.getHeight();
BufferedImage bimg = null;
Image img = imagePlus.getImage();
//creating a new bufferedimage from above image
//if you pass BufferedImage.TYPE_INT_RGB in place of Type_BYTE_GRAY then
//you will get your original colored image
bimg = new BufferedImage((int)image_width, (int)image_height,
BufferedImage.TYPE_BYTE_GRAY);
//getting graphics from Image
Graphics2D gg = bimg.createGraphics();
//drawing your image on this new graphics
gg.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
//file name for saving jpeg file on to hard disk
String temp = "white.jpeg";
File fi = new File("d:\\" + temp);
ImageIO.write(bimg, "jpg", fi);
Hope it will for you too.
Prashant Chandrakar
9270710943
Pune.
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of
amol.patil
Sent: Tuesday, April 07, 2009 4:18 PM
To:
[hidden email]
Subject: Reg:Convert color to black and white
Hi All,
By using IMAGEJ I want to convert color JPEG file in to black
and white tiff or black and white PNG,
For this I have written following code
BufferedImage image = ImageIO.read(new File("G:\\ImageJTest\\1.jpg"));
ImagePlus imagePlus = new ImagePlus();
imagePlus.setImage(image);
ImageProcessor imageProcessor = imagePlus.getProcessor();
imageProcessor.autoThreshold();
But I am not getting how I can save result of this threshold
operation.
Thanks and Regards,
Amol Patil