read10bitImage() in ImageReader ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

read10bitImage() in ImageReader ?

Hidenao IWAI
Dear All,

Recently, I deal with packed 10-bit images (5 bytes/4 pixels) acquired by an ultra fast camera. This camera also outputs 12-bit packed images (3 bytes/2 pixels).
I have already read the packed 12-bit files by using FileOpener with FileInfo.filetype = GRAY12_UNSIGNED.
I'm wondering if you could add read10bitImage() in ImageReader.java as well as read12bitImage().

Best regards,
Hidenao Yamada

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: read10bitImage() in ImageReader ?

Hidenao IWAI
I coded read10bitImage() for ij.io.ImageReader.java as follows,

        short[] read10bitImage(InputStream in) throws IOException {
    int bytesPerLine = (int)(width*1.25);
    if ((width&3)!=0) bytesPerLine += (4-width&3); // add 4-widht%4
        byte[] buffer = new byte[bytesPerLine*height];
        short[] pixels = new short[nPixels];
        DataInputStream dis = new DataInputStream(in);
        dis.readFully(buffer);
        for (int y=0; y<height; y++) {
            int index1 = y*bytesPerLine;
            int index2 = y*width;
            int count = 0;
        while (count<width) {
                pixels[index2+count] = (short)(((buffer[index1]&0xff)*4)   + ((buffer[index1+1]>>6)&0x03));
                count++;
                if (count==width) break;

                pixels[index2+count] = (short)(((buffer[index1+1]&0x3f)*16) + ((buffer[index1+2]>>4)&0x0f));
                count++;
                if (count==width) break;

                pixels[index2+count] = (short)(((buffer[index1+2]&0x0f)*64)  + ((buffer[index1+3]>>2)&0x3f));
                count++;
                if (count==width) break;

                pixels[index2+count] = (short)(((buffer[index1+3]&0x03)*256) + (buffer[index1+4]&0xff));
                count++; index1+=5;
            }
        }
        return pixels;
    }

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html