JAVA: Read and Write PPM, PGM images in JAVA

Download the code library from HERE
Also you can download some sample PPM and PGM images from here.

The following helps to setup the project using Eclipse.
This requires 2 Image Processing libraries which are included in the zip. [jai_imageio.jar and clibwrapper_jiio.jar]
If you are not using eclipse, please add these 2 libraries to your project.

After opening Eclipse:

1. Goto File->New->Java Project
2. In the "contents" section, select the radio button "create project from existing source"
3. Click browse to point to the downloaded ImgProcTool folder (Assuming u have unzipped the file)
4. Click Finish on the "new Java Project" window.

TEST IT BY EXECUTING THE PROJECT
A simple sample program IpToolTester.java is included, which reads and writes a sample PGM image.
 public class IpToolTester {  
     public static void main(String[] args) {  
           ImageTool imageTool = new ImageTool();  
           String srcPath = "lena_384.pgm";  
           
           Image srcImg = new Image(srcPath);  
           Image tgtImg = new Image();  
           tgtImg.init(srcImg.getNumRows(), srcImg.getNumCols());  
           imageTool.copyImg(srcImg, tgtImg);  
           tgtImg.save("lena_write.pgm");  
           System.out.println("Done");  
      }  
 }  
5. Right click on the project and select "Run as->java application"
6. If everything is fine, there will be console output ending with "Done".
7. Refresh the project, you will see a new .pgm file "lena_write.pgm".

No comments:

Post a Comment

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...