Square root will give you a non-linear translation into the destination
space.  Also, adding 32768 will mean that 32767 or 0x7fff will map to
full intensity, 0 will map to half intensity, and -32768 will map to
blackness - is that the mapping you want?  If you want to convert a
signed short directly to its "unsigned short" equivalent value then
the way to do this is by using:

       short s = /* some number */;
       int si = s;
       int ui = s & 0xffff;

In that case ui will represent the bits of s interpreted as an unsigned
value and si will represent the same numeric value as s.  If you want to
reduce this value then to 8 bits in a linear way, a simple shift would
work best:

       int ui = (s & 0xffff) >> 8;

Is that the conversion you wanted?

                                       ...jim

--On Wednesday, November 6, 2002 5:09 AM +0900 Kevin Kim <[EMAIL PROTECTED]> wrote:

Hi, all.

I have 224 matrixes each of which is consisted of h by w Short, 16 Signed bit pixel loaded into memory.  Among these 224 matrix, I am selecting three matrixes to map into RGB value.

My understanding was that since I have a range from -32767 to 32767 for each R, G, B, I presumed, I would have to sqaure root to fit into 8 bit red representation ranging 0 to 255, green, and blue.  This is shown below.

I created the bufferedImage class and am using the defaultToolKit.  I ran into some odd problems.

The image is supposed to vary in color, depending on what I have selected for red, green, and blue.  However, the rendered image always seems dim.

Was I supposed to normalize each three matrix instead of just algebraicly  square root?

Or  is is possible to create ColorModel and SampleModel in 48 bit representation for RGB?  (=16 bit Short * 3 for RGB)

Here is code snipet.

 /***********************************************************
   * Create dataBuffer for BufferedImage before invoke paint()
   */
  public void createDataForBufferedImage(SingleBandDataMatrix[] sbdm)
  {
    //This defindes the image size
    int width  = this.getPassedHeader().getSamples();
    int height = this.getPassedHeader().getLines();

    // This is the band index I choosed to load among 224 different matrix
    int redBandMatrixIndex  = this.getPassedSelectedRedBandNumber();
    int greenBandMatrixIndex= this.getPassedSelectedGreenBandNumber();
    int blueBandMatrixIndex = this.getPassedSelectedBlueBandNumber();

    //Declare temporary matrix to copy the original matrixs selected for Red, green, and blue
    int[][] redTempMatrix = new int[width][height];
    int[][] blueTempMatrix = new int[width][height];
    int[][] greenTempMatrix = new int[width][height];

   //Copy over the selected matrix to temporary matrix for red, green, and blue
    redTempMatrix = (int[][])sbdm[redBandMatrixIndex-1].getMatrix();
    greenTempMatrix = (int[][])sbdm[greenBandMatrixIndex-1].getMatrix();
    blueTempMatrix = (int[][])sbdm[blueBandMatrixIndex-1].getMatrix();

    //Below is the actual DataBuffer going into BufferedImage
    int[] data = new int[width*height];


    //Pack the ARGB into 32 bit(4 byte)
    int i=0;
    int z=0;
    //int[] red= new int[height*width];
     for (int y=0; y<height ;y++ )
     {
        for (int x=0; x<width ;x++ )
        {

          /*******************************************************
           * Need to pack the 2 byte of signed integer into 1 byte
           *******************************************************/
         // I am just adding 32768 to convert from Signed Short to UnSigned Short
        // And squre root to convert current 0-65536 to 0-255 value for integer.
          int red   = (int)Math.sqrt((double) redTempMatrix[x][y] +32768 )    ;
          int green = (int)Math.sqrt((double) greenTempMatrix[x][y]+32768 )   ;
          int blue  = (int)Math.sqrt((double)  blueTempMatrix[x][y]+32768 )   ;


          //Then pack into one RGB integer type pixel
          data[i++] = (red<<16)|(green<<8)|(blue);

        }

     }
     image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
     image.setRGB(0,0,width, height,data,0,width);

  }
  public void paint(Graphics g)
  {
    g.drawImage(image,0,0,this);
  }

Thanks in advance..
Kevin

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to