Re: Reading a binary file
Posted by
Fernando Sales on
Jun 02, 2009; 5:27pm
URL: http://imagej.273.s1.nabble.com/Reading-a-binary-file-tp3692318p3692319.html
Kb,
the easiest way in my option is to use the Import > Raw available into IJ.
If you are intended to use it inside of a plugin, you can directly
instanciate the Import class and call its execution from your code.
Another optiion is to use the "Record Macro" resource and open one image
using the File > Import > Raw command and after this, get the plugin or
macro code from this operation.
I hope this helps you.
Best regards,
Fernando
On Tue, Jun 2, 2009 at 10:26 AM, Kb Pru <
[hidden email]> wrote:
> Hello All,
> I am new to writing plugins and am trying to read a raw file in through a
> plugin. I have several questions:
>
> 1. Each file I am reading is 105906380 bytes long. It takes a while to read
> the file. How can I speed it up? I am currently reading the file slice by
> slice via these commands:
>
> for (int s=0;s<slices;s++){
> img.setSlice(s+1);
> IJ.showProgress( (double) s / slices);
> pixels = (short[]) img.getProcessor().getPixels();
> for(int row=0;row<height;row++){
> offset = (row*width);
> for (int col=0;col<width;col++){
> pixels[offset+col]=swapshort(input.readShort());
> }
> }
> }
>
> 2. I would like to scale the pixel value linearly. However when I change
> one
> line line from the above snipped to :
> pixels[offset+col]=swapshort(input.readShort()-16383);
> I get an error message "Incompatible type for method. Explicit cast needed
> to convert int to short.". How do I operate on pixel element values.
>
> Many thanks.
>
> KB
>