Contrast PlugIn

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

Contrast PlugIn

Priscila Gomes



Hi!
The objective of the plugin I'm writing is to take a slice from a stack and then create a new stack with multiple images of the same slice but with different contrasts.Firstly, I tried to put the altered images on a stack, with a for loop. But all the images get the same contrast definitions (max and min) as the first one added.So, my second approach, was to create the stack with the original image, and then alter its contrast definition. This does quite except, that when it's done, the stack gets the same min max definitions as the last slice modified.I don't know what I'm missing.Can someone help me?
This is the code I wrote:
public void run(ImageProcessor ip) { ImageProcessor ip2 = ip.duplicate(); ImageStack nstack = new ImageStack(stack.getWidth(),stack.getHeight()); for(int i=0; i<100; i++){ nstack.addSlice(ip2);                    //creates the stack } ImagePlus imp2= new ImagePlus("teste", nstack); imp2.show();                     //the image is shown modifying the contrast for(int j=0; j<100;j++){ imp2.setSlice(j);    IJ.run(imp2, "Enhance Contrast", "saturated="+j+" normalize"); }}
Regards,
Priscila Gomes, MSc student
Portugal
     
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Contrast PlugIn

Michael Schmid
Hi Priscila,

the Brightness & Contrast settings determine how the data are displayed, they do not affect the actual data (RGB images are an exception).

If you have 8-bit images, you can apply the B&C changes for a single stack slice to modify the data according to the B&C setting.
  IJ.run(imp2, "Apply LUT", "slice");

For 16-bit images and 32-bit images, you need some image calculations, i.e. subtract the lower limit of the display range and multiply with a factor>1 to enhance the contrast. The factor is
  data_range /(upper_limit - lower_limit)
where data_range is the range to show all data without saturated pixels, and you can retrieve the upper and lower limit after setting B&C with ip.getMin(), ip.getMax() (ip is the ImageProcessor)

Michael
________________________________________________________________
On Apr 14, 2015, at 19:34, Priscila Gomes wrote:

> Hi!
> The objective of the plugin I'm writing is to take a slice from a stack and then create a new stack with multiple images of the same slice but with different contrasts.Firstly, I tried to put the altered images on a stack, with a for loop. But all the images get the same contrast definitions (max and min) as the first one added.So, my second approach, was to create the stack with the original image, and then alter its contrast definition. This does quite except, that when it's done, the stack gets the same min max definitions as the last slice modified.I don't know what I'm missing.Can someone help me?
> This is the code I wrote:
> public void run(ImageProcessor ip) { ImageProcessor ip2 = ip.duplicate(); ImageStack nstack = new ImageStack(stack.getWidth(),stack.getHeight()); for(int i=0; i<100; i++){ nstack.addSlice(ip2);                    //creates the stack } ImagePlus imp2= new ImagePlus("teste", nstack); imp2.show();                     //the image is shown modifying the contrast for(int j=0; j<100;j++){ imp2.setSlice(j);    IJ.run(imp2, "Enhance Contrast", "saturated="+j+" normalize"); }}
> Regards,
> Priscila Gomes, MSc student
> Portugal
>    
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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