This discussion is archived
8 Replies Latest reply: Apr 2, 2013 11:05 AM by gimbal2 RSS

Need Help for Image Processing

994602 Newbie
Currently Being Moderated
Hi everyone,

my name is Davide and I am a new member. I apologize in advance for my English that It's not very good.

I have to do an exercise where I have to draw a SAR(Synthetic Aperture Radar) Image. The problem is that the input image is composed by a binary raster plus an XML parameters file. The XML file contains all the information to correctly read the image.

I downloaded Java Advancing Imaging Library but I've never worked with this image format and I don't know where to start.

Can anyone help me? How should i do with the binary raster file? How can i read it?

Thank you very much.
  • 1. Re: Need Help for Image Processing
    gimbal2 Guru
    Currently Being Moderated
    991599 wrote:
    Hi everyone,
    Hello.
    >
    my name is Davide and I am a new member. I apologize in advance for my English that It's not very good.
    Everyone that says this is actually very good. You are no different. Have faith in your abilities!

    >
    I have to do an exercise where I have to draw a SAR(Synthetic Aperture Radar) Image. The problem is that the input image is composed by a binary raster plus an XML parameters file. The XML file contains all the information to correctly read the image.

    I downloaded Java Advancing Imaging Library but I've never worked with this image format and I don't know where to start.
    Googling about the file format would be a good place to begin. Its best to start with the theory and only then move on to the actual technical implementation part (Java in your case).
    >
    Can anyone help me? How should i do with the binary raster file? How can i read it?
    I'm not sure you can using standard APIs. You might need very specific tools / libraries to be able to work with such specific formats which may be commercial in nature. a Google for "java sar image library" returns some results, such as this:

    http://code.google.com/p/eoraster/

    That's a good tip by the way: if you're looking for something to be implemented in Java, start your google search with the literal word "java" followed by what you want.
  • 2. Re: Need Help for Image Processing
    994602 Newbie
    Currently Being Moderated
    Hi everyone again,
    I followed your advice and I studied the theory on raster data so I have made some step forward. Now I have a new problem that I will try to explain you in the better way. I was able to obtain from the binary raster data an array of float.

    From the XML parameters file I know that the rows number are 1000, the columns number are 2000, the pixel type is complex float and that the real and imaginary parts are put side-by-side on a column basis. I created two array, one of the real parts and one of the imaginary parts:
    for (int i=0;i < SIZE_X*SIZE_Y; i++){
       if(i%2 == 0){
          real[k] = bin_input;
    if(Math.abs(real[k]) > max_value_re){
    max_value_re = Math.abs(real[k]);
    }
    k++;
    }else{
    img[n] = bin_input[i];
    if(Math.abs(img[n]) > max_value_im){
    max_value_im = Math.abs(img[n]);
    }
    n++;
    }
    }
    Then I create an array with the absolute value of complex number:
    for (int i=0;i < SIZE_X/2*SIZE_Y; i++){
    mag[i] = (float) (Math.sqrt(Math.pow(real[i]/max_value_re,2) + Math.pow(img[i]/max_value_im,2)));
    }
    Now I have an array of float with values from 0 and 1. I tried to create a gray scale image because in the XML file it says that the number of channels is 1:
    BufferedImage theImage = new BufferedImage(SIZE_X/2, SIZE_Y, BufferedImage.TYPE_4BYTE_ABGR);
    WritableRaster wr = (WritableRaster) theImage.getData();
    wr.setPixels(0, 0, SIZE_X/2, SIZE_Y, mag);
              
    File outputfile = new File("C:\\Sviluppo\\workspace\\Java\\SAR\\Milano.png");
    try {
    ImageIO.write(theImage, "png", outputfile);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    The problem is that the image is all black as if the method is not able to interpret the float values ​​and puts everything at zero. 
    
    First of all, do you think the process can be right or is there some logical/theorical error? If it's ok, How can I fix the problem?
    
    Thank you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  • 3. Re: Need Help for Image Processing
    gimbal2 Guru
    Currently Being Moderated
    Grayscale image? Yet your image is of type:
    BufferedImage.TYPE_4BYTE_ABGR
    That's not grayscale, that's 32 bits color data including an alpha channel. You will have to translate the data to 32 bits yourself if you want to store it in this format. Besides that I find the usage of floats a bit odd, whenever i had to work with images it was always about bytes. Either 4 bytes each representing a different color component, or a single byte representing a grayscale value or an index into a palette lookup table.

    So yeah - research more about how images are stored, especially grayscale ones. Luckily that is a far more common topic.
  • 4. Re: Need Help for Image Processing
    994602 Newbie
    Currently Being Moderated
    gimbal2 wrote:
    Grayscale image? Yet your image is of type:
    BufferedImage.TYPE_4BYTE_ABGR
    I pasted the wrong version, in the right version I wrote
      BufferedImage.TYPE_BYTE_GRAY 
    but it doesn't work.

    I take advantage of your availability, from this XML, what do you understand?
    <NumberOfChannels>1</NumberOfChannels>
    
      <VersionNumber>2.1</VersionNumber>
    
      <Description></Description>
    
      <Channel Number="1" Total="1">
        <RasterInfo>
          <FileName>CUT_MILANO_0001</FileName>
          <Lines>1000</Lines>
          <Samples>2000</Samples>
          <HeaderOffsetBytes>0</HeaderOffsetBytes>
          <RowPrefixBytes>0</RowPrefixBytes>
          <ByteOrder>LITTLEENDIAN</ByteOrder>
          <CellType>FLOAT_COMPLEX</CellType>
          <LinesStep unit="s">0.0003272</LinesStep>
          <SamplesStep unit="s">6.83760683760684e-009</SamplesStep>
          <LinesStart unit="Utc">18-AUG-2008 05:16:12.978397453000</LinesStart>
          <SamplesStart unit="s">0.004742593128205132100</SamplesStart>
        </RasterInfo>
    I understand that the image is in gray scale, for you?
  • 5. Re: Need Help for Image Processing
    994602 Newbie
    Currently Being Moderated
    A clarification, in the file reading, I keep in mind the byte order (LITTLE_ENDIAN):
    float[] bin_input = new float[SIZE_X * SIZE_Y];
    try{
       FileImageInputStream fin = new FileImageInputStream(new File(address));
       fin.setByteOrder(ByteOrder.LITTLE_ENDIAN);
       for(int i = 0; i < SIZE_X * SIZE_Y; i++) {
         bin_input[i] = fin.readFloat();
       }
         fin.close();
       }catch (Exception e) {
         System.out.println("Exception: " + e);
       }
    So the problem is not due to this.
  • 6. Re: Need Help for Image Processing
    Maxideon Explorer
    Currently Being Moderated
    A grayscale image is backed by a byte[] array. Each byte represents a pixel with a color value in the range [0,255]. This method
    setPixels(x,y,w,h, float[])
    will ultimately convert your floats to bytes, probably through simple casts. In other words your float data needs to represent the same: a color value in the range [0,255]. If you get a black image, it's probably because the magnitude of your complex numbers are all < 1.
  • 7. Re: Need Help for Image Processing
    1000594 Newbie
    Currently Being Moderated
    Id like to know this too :)
  • 8. Re: Need Help for Image Processing
    gimbal2 Guru
    Currently Being Moderated
    Well, maxideon's reply is your best bet, unless you can prove he is mistaken.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points