jpeg manipulation using java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vbnandu86
    New Member
    • Jan 2008
    • 2

    #1

    jpeg manipulation using java

    some of my friends have planned to do A F.R. project using a simple algorithm Eigen Faces usnig Principal Component Analysis( by turk and Petland )

    I have used the following code to extract pixel values from a Jpeg image , but it gives me negative values wen i print the pixel values!!
    I dont know if I can continue with negative values for further computation like finding the co-variance matrix ...eigen vectors etc... ...
    If u know anything please reply.....

    Code:
    private byte bytes[]=null;
    private double doubles[] = null;
    private String filename=null;
    private int height = 0;
    private int width = 0;
    
    
    private void readImage() throws FileNotFoundException, IOException {
    
    FileInputStream fIn = new FileInputStream(filename);
    JPEGImageDecoder jpeg_decode = JPEGCodec.createJPEGDecoder(fIn);
    BufferedImage image = jpeg_decode.decodeAsBufferedImage();
    
    
    width = image.getWidth();
    height = image.getHeight();
    
    int[] rgbdata = new int[width * height];
    
    image.getRGB(0,0,width,height,rgbdata,0,width);
    
    
    bytes = new byte[rgbdata.length];
    doubles = new double[rgbdata.length];
    
    for (int i = 0; i < bytes.length; i++) {
    bytes = (byte) (rgbdata & 0xFF);
    doubles = (double)(rgbdata);
    }
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    1. I think you are using old code for reading a jpeg that is not part of the J2SE. You can now use class javax.imageio.I mageIO:

    [CODE=Java]BufferedImage image = ImageIO.read(ur l_or_file_etc.. .);[/CODE]

    2. Your code doesn't compile (rgbdata is an array so you can't write "rgbdata & 0xFF"), but I'm guessing your problem is the following. You have some data in a byte. In Java bytes are always signed, so they hold a value in the range [-128,127]. Nevertheless, most programmers use them as though they held a value in the range [0,255]. To obtain this "unsigned" value, do the following:

    [CODE=Java]byte b = ...
    int value = b & 0xff;[/CODE]

    I hope the problem doesn't really have to do with your algorithm, which went flying over my head.

    If you still have a problem, post a SSCCE: http://mindprod.com/jgloss/sscce.html

    Comment

    • vbnandu86
      New Member
      • Jan 2008
      • 2

      #3
      Thanks!!!!!!!!! !! i'll be back if i have any more queries

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

        This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

        MODERATOR

        Comment

        Working...