Reading a binary file
Posted by Kb Pru on Jun 02, 2009; 1:26pm
URL: http://imagej.273.s1.nabble.com/Reading-a-binary-file-tp3692318.html
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