Posted by
Kenneth Sloan-2 on
URL: http://imagej.273.s1.nabble.com/Problem-with-Maximum-intensity-projection-tp5020309p5020317.html
As usual, I tend to go for a Java plugin solution. Here's a first cut:
/**
* File: Maximum_Wavelength.java
* Author: K.R. Sloan
* Last Modified: 22 March 2018
*
* Desc: An ImageJ plugin that processes an ImageStack and produces an image
* where each pixel is an index naming the slice containing the maximum value
*/
import ij.*;
import ij.plugin.filter.PlugInFilter;
import ij.process.*;
public class Maximum_Wavelength implements PlugInFilter
{
private ImagePlus imp;
@Override
public int setup(String arg, ImagePlus imp)
{
if(arg.equals("about"))
{showAbout(); return DONE;}
this.imp = imp;
return STACK_REQUIRED + NO_CHANGES + NO_UNDO + DOES_ALL;
}
@Override
public void run(ImageProcessor ip)
{
ImageStack is = this.imp.getImageStack();
int height = is.getHeight();
int width = is.getWidth();
int depth = is.getSize();
ImageProcessor resultIP = new ByteProcessor(width,height);
for(int y=0;y<height;y++)
{
for(int x=0;x<height;x++)
{
float[] spectrum = getSpectrum(is,x,y);
int maxIndex = maxIndex(spectrum);
resultIP.putPixel(x,y,maxIndex);
}
IJ.showProgress((double)y/(double)height);
}
ImagePlus resultIPL = new ImagePlus("Maximum Wavelength", resultIP);
resultIPL.show();
return;
}
private void showAbout()
{
IJ.showMessage("About Maximum_Wavelength...",
"This plugin filter processes a Stack and produces a new image" +
"where each pixel is a slice index indicating the slice" +
"containing the maximum value"
);
}
private float[] getSpectrum(ImageStack is, int x, int y)
{
int size = is.getSize();
float[] result = new float[size];
for(int j=0;j<size;j++)
result[j] = is.getProcessor(j+1).getPixelValue(x,y);
return result;
}
private int maxIndex(float[] v)
{
float maxV = 0.0f;
int maxIndex = -1;
for(int i=0;i<v.length;i++)
if(v[i]>maxV) { maxV = v[i]; maxIndex = i; }
return maxIndex;
}
}
Obligatory question: I tried to use getVoxels - but failed miserably. After a few attempts, I just
rolled my own.
This is slower than dirt - but I hope it's clear.
And, as always - I welcome corrections to my chronic mis-understanding of the API.
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.
> On 23 Mar 2018, at 02:09 , Parijat Sarkar <
[hidden email]> wrote:
>
> Dear all,
>
> I have set of 10 images (of identical cells) with different emission ranges.
> For example, image 1 is of 500 nm, image 2 is of 510 nm and so on...
>
>
> [These 10 images are nothing but spectral images covering the entire
> emission spectra of a fluorophore].
>
>
> In conventional analysis, we generate something known as a maximum
> intensity projection - maximum intensity across all the sections for a
> particular pixel is assigned to a new image (continued for all the pixels).
>
>
>
> *What I want is rather than the intensity information, I need a image with
> the information that would reflect from which section the intensity was
> chosen. This would result in an image with all the maximum wavelength
> information. *
>
>
> Thank you so much !
>
>
> Parijat Sarkar
>
> Graduate Student
>
> CSIR-CCMB
>
> India
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html