Posted by
Kenneth Sloan-2 on
URL: http://imagej.273.s1.nabble.com/macro-convert-calibrated-value-to-raw-pixel-value-tp5022651p5022657.html
As long as I have pushed this exercise this far - I might as well give the OP an answer to his question.
And...also demonstrate (in Java) what I would like to be able to do in the macro language). Java is often maligned
as being too verbose - and there is something to this criticism. For a tiny program like this, *almost* everything
translates line-by-line into the macro language, while at the same time eliminating some of the (tedious?) type information.
I tend to argue that this verbosity is more of a feature than a bug - but, I can see the point that perhaps the macro
language is more suitable for such a quick-and-dirty implementation. So, I would really like to see changes to the macro language that would allow this program to be written there.
There are two issues:
a)[important] - add putValue(x,y,calibratedValue)
b)[not as critical] - allow easy and efficient access to more than one image at at time, at pixel-by-pixel granularity.
For the original poster, who asked for OCT images in the range -64..+64 to be mapped to an 8-bit banded grayscale image, with
counts for each category of pixel values - here is a Java plugin that does what I think you wanted.
And now a question: what type of OCT produces these values? My OCT experience is limited to Ophthalmic devices such as
Spectralis and Nidek - which provide OCT images on a completely different scale. I would love to hear the details of your device, and perhaps see a few images. If interested - contact me off-list.
=================================================================================
// File: Six_Bands.java
// Author: K R Sloan
// Last Modified: 11 November 2019
// Purpose: convert an image to 8-bit
// map values:
// in <= 0.0 -> out = 0.0
// 0.0 < in <= 10.0 -> out = 50.0
// 10.0 < in <= 20.0 -> out = 100.0
// 20.0 < in <= 30.0 -> out = 150.0
// 30.0 < in <= 40.0 -> out = 200.0
// 40.0 < in -> out = 250.0
import ij.*;
import ij.process.*;
import ij.plugin.*;
public class Six_Bands implements PlugIn
{
private static int sixBands(double inValue, long[] counts)
{
if(inValue <= 0.0) {counts[0]++; return 0;}
if(inValue <= 10.0) {counts[1]++; return 50;}
if(inValue <= 20.0) {counts[2]++; return 100;}
if(inValue <= 30.0) {counts[3]++; return 150;}
if(inValue <= 40.0) {counts[4]++; return 200;}
counts[5]++; return 250;
}
public void run(String arg)
{
ImagePlus ipl = IJ.getImage();
ImageProcessor ip = ipl.getProcessor();
int width = ip.getWidth();
int height = ip.getHeight();
String title = ipl.getTitle();
String titleOut = title + "_SixBands";
ByteProcessor bp = new ByteProcessor(width, height);
long[] counts = new long[6];
for(int i=0;i<counts.length;i++) counts[i]=0;
for(int y=0;y<height;y++)
for(int x=0;x<width;x++)
{
double inValue = ip.getValue(x,y);
int outValue = sixBands(inValue,counts);
bp.putPixel(x,y,outValue);
}
ImagePlus iplOut = new ImagePlus(titleOut, bp);
iplOut.show();
IJ.log("low\thigh\tcount");
IJ.log("-inf\t 0.0\t" + counts[0]);
IJ.log(" 0.0\t10.0\t" + counts[1]);
IJ.log("10.0\t20.0\t" + counts[2]);
IJ.log("20.0\t30.0\t" + counts[3]);
IJ.log("30.0\t40.0\t" + counts[4]);
IJ.log("40.0\t+inf\t" + counts[5]);
}
}
=================================================================================
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html