Quick Help? Pixel Subtraction

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

Quick Help? Pixel Subtraction

Gary Laevsky
Hello All,

Is there a macro that exists (who's values can be altered) that
analyzes an image, and if a pixel equals a certain value, it will be deleted?

Our homemade system has some inherent noise in the PMT, to the tune
of about 1000 pixels out of 30,000 or so.  I'd like to "delete" the
255s.  In many cases, the next pixel value is about 150, so I'm also
having some "stretch" issues.  If I could just delete the 255s....

I searched the archives to no avail.

Thanks much in advance.
Best,

Gary



Gary Laevsky, Ph.D.
Keck Facility Manager, CenSSIS
Northeastern University
302 Stearns
360 Huntington Ave.
Boston, MA 02115
voice(617) 373 - 2589<br>
fax(617) 373 - 7783<br><br>

http://www.censsis.neu.edu

http://www.ece.neu.edu/groups/osl

http://www.keck3dfm.neu.edu
Reply | Threaded
Open this post in threaded view
|

Re: Quick Help? Pixel Subtraction

Gabriel Landini
On Monday 12 December 2005 20:54, Gary Laevsky wrote:
> Our homemade system has some inherent noise in the PMT, to the tune
> of about 1000 pixels out of 30,000 or so.  I'd like to "delete" the
> 255s.  In many cases, the next pixel value is about 150, so I'm also
> having some "stretch" issues.  If I could just delete the 255s....

Not sure if these 3 options would to what you want, but be aware that these
methods "invent" values for the noisy pixels...

A) simplest:
* duplicate original and call it image1
* threshold the image1 at 255,255
* subtract original-image1 (pixels at 255 will now be 0).


B) 8 bit & 24 bit image denoising
////////////////////////////////////////////////////////////////////////////
// SaturatedSinglePixelDenoising.txt
// G. Landini 16/July/2005
// This macro detects saturated *single* pixels (8 connected) in the
// image (grey=255) and replaces them with the pixel value of
// either the mean or the median of the neighbours (choose which
// method one by  un-commenting the lines indicated below.
// Works with 8bit and 24 bit images only.
// Needs the Particles8 plugin available at:
// http://www.dentistry.bham.ac.uk/landinig/software/software.html
run("Duplicate...", "title=Denoised");
setBatchMode(true);
run("Duplicate...", "title=pixels");
if (bitDepth==24) run("8-bit");
setThreshold(255, 255);
run("Threshold", "thresholded remaining");
//---
// if you want to denoise small clusters of pixels, rather than single pixels,
// then comment the following 5 lines, but be aware that the average
// or median will not be correct as other pixels in the cluster may
// contribute to the corrected value:
run("Duplicate...", "title=non-single");
run("Particles8 ", "white show=Particles filter minimum=2 maximum=999999
overwrite");
imageCalculator("Subtract", "pixels","non-single");
selectWindow("non-single");
close();
//---
selectWindow("Denoised");
run("Duplicate...", "title=median");
// use average of the 8 neighbours
run("Convolve...", "text1=[1 1 1 1 0 1 1 1 1] normalize");
// use median of the 3x3 neighbourhood
//run("Median...", "radius=1");
if (bitDepth==24){
  selectWindow("pixels");
  run("RGB Color");
}
imageCalculator("AND create", "pixels","median");
imageCalculator("Subtract", "Denoised","pixels");
imageCalculator("Add", "Denoised","Result of pixels");
selectWindow("median");
close();
selectWindow("Result of pixels");
close();
selectWindow("pixels");
close();
setBatchMode(false);
////////////////////////////////////////////////////////////////////////////


C) 8 bit images only denoising
////////////////////////////////////////////////////////////////////////////
// SaturatedPixelsDenoising.txt
// G. Landini 16/July/2005
// This macro detects saturated  pixels (8 connected) in the
// image (grey=255) and replaces them with the pixel value of
// the mean of the neighbours which are not saturated..
// Works with 8bit images only.
// Needs the BinaryConnectivity plugin available at:
// http://www.dentistry.bham.ac.uk/landinig/software/software.html
t=getTitle();
if (bitDepth()==24){
  run("RGB Stack");
  setSlice(1);
  denoiser();
  selectWindow("Denoised");
  rename("red");
  selectWindow(t);
  setSlice(2);
  denoiser();
  selectWindow("Denoised");
  rename("green");
  selectWindow(t);
  setSlice(3);
  denoiser();
  selectWindow("Denoised");
  rename("blue");
  run("RGB Merge...", "red=red green=green blue=blue");
  rename("Denoised");
  selectWindow(t);
  run("RGB Color");
}
else {
  if (bitDepth()==8) denoiser();
}

function denoiser () {
  run("Duplicate...", "title=Denoised");
  setBatchMode(true);
  xe=getWidth();
  ye=getHeight();
  cycle=true;

  while (cycle){
    selectWindow("Denoised");  
    run("Duplicate...", "title=pixels");
    setThreshold(255, 255);
    run("Threshold", "thresholded remaining");
    selectWindow("Denoised");
    run("Duplicate...", "title=median");
    // use average of the 8 neighbours
    run("Convolve...", "text1=[1 1 1 1 0 1 1 1 1] normalize");
    imageCalculator("AND create", "pixels","median");
    imageCalculator("Subtract", "Denoised","pixels");
    imageCalculator("Add", "Denoised","Result of pixels");
    selectWindow("median");
    close();
    selectWindow("Result of pixels");
    close();
    selectWindow("pixels");
    run("BinaryConnectivity ", "white");
    cycle=false;

    for (x=0;x<xe;x++){
      for (y=0;y<ye;y++){
        n=getPixel(x,y);
        if (n>1){
          if(n<9){
            selectWindow("Denoised");
            putPixel(x,y,(getPixel(x,y)*8 - ((n-1)*255))/(9-n));
            updateDisplay();
            selectWindow("pixels");
          }
          else cycle=true;
        }
      }
    }
    selectWindow("pixels");
    close();
  }
  setBatchMode(false);
  updateDisplay();
}
////////////////////////////////////////////////////////////////////////////

Cheers,

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Quick Help? Pixel Subtraction

Henry Barwood
I tried out the "simple" method below and found it to work fairly well with
some CL images I have. Only had two problems that turned up. When the
thresholded image is subtracted (to eliminate "hot spots" from sample
contamination) it leaves disconcertingly dark "holes" in the image. Is
there: 1)A simple way to "blur" the image to be subtracted so that it
feathers into the surrounding area? 2)A way to cause the thresholded image
to take on a more neutral value so that it is not so obvious in the
processed image?

My contaminated images contain intense green spots. Can I extract the green
values from a RGB image and threshold only those areas?

Henry Barwood
Associate Professor of Science, Earth Science
Department of Math and Physics
MSCX 312G
Troy University
Troy, Alabama  36082
[hidden email]

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]]On Behalf Of
Gabriel Landini
Sent: Monday, December 12, 2005 4:58 PM
To: [hidden email]
Subject: Re: Quick Help? Pixel Subtraction


On Monday 12 December 2005 20:54, Gary Laevsky wrote:
> Our homemade system has some inherent noise in the PMT, to the tune
> of about 1000 pixels out of 30,000 or so.  I'd like to "delete" the
> 255s.  In many cases, the next pixel value is about 150, so I'm also
> having some "stretch" issues.  If I could just delete the 255s....

Not sure if these 3 options would to what you want, but be aware that these
methods "invent" values for the noisy pixels...

A) simplest:
* duplicate original and call it image1
* threshold the image1 at 255,255
* subtract original-image1 (pixels at 255 will now be 0).
Reply | Threaded
Open this post in threaded view
|

Re: Quick Help? Pixel Subtraction

Gabriel Landini
On Tuesday 13 December 2005 17:36, Henry Barwood wrote:
> I tried out the "simple" method below and found it to work fairly well with
> some CL images I have. Only had two problems that turned up. When the
> thresholded image is subtracted (to eliminate "hot spots" from sample
> contamination) it leaves disconcertingly dark "holes" in the image. Is
> there: 1)A simple way to "blur" the image to be subtracted so that it
> feathers into the surrounding area?

If the noise is relegated to a single pixel, why do you want to subtract a
value from the neighbouring pixels?

Try the other methods, they replace the hot pixels with the average or median
of the neighbours.

> 2)A way to cause the thresholded image
> to take on a more neutral value so that it is not so obvious in the
> processed image?

Sorry I don't understand what that means. Thresholds are yes/no only...

Cheers,

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Quick Help? Pixel Subtraction

Henry Barwood
I tried to distinguish "hot spots" from "hot pixels", apparently
unsuccessfully. My samples are petrographic slides that are contaminated
with particles of alumina polish. The particles luminesce a brilliant,
bright green, but are of irregular size and dimension. I only want to modify
the "hot Spots" not the remaining image, hence, I'm reluctant to use any
other noise reduction or background subtraction filters.

When I remove the hot spots using the threshold technique it leaves a
completely black spot in place of the bright green spot. I would like to
replace the removed area with a less conspicuous area that more accurately
matches the surrounding image. Don't know if I explained that properly, but
I'm sort of struggling for terminology here!

Henry

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]]On Behalf Of
Gabriel Landini
Sent: Tuesday, December 13, 2005 11:53 AM
To: [hidden email]
Subject: Re: Quick Help? Pixel Subtraction


On Tuesday 13 December 2005 17:36, Henry Barwood wrote:
> I tried out the "simple" method below and found it to work fairly well
with
> some CL images I have. Only had two problems that turned up. When the
> thresholded image is subtracted (to eliminate "hot spots" from sample
> contamination) it leaves disconcertingly dark "holes" in the image. Is
> there: 1)A simple way to "blur" the image to be subtracted so that it
> feathers into the surrounding area?

If the noise is relegated to a single pixel, why do you want to subtract a
value from the neighbouring pixels?

Try the other methods, they replace the hot pixels with the average or
median
of the neighbours.

> 2)A way to cause the thresholded image
> to take on a more neutral value so that it is not so obvious in the
> processed image?

Sorry I don't understand what that means. Thresholds are yes/no only...

Cheers,

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Quick Help? Pixel Subtraction

Gabriel Landini
On Tuesday 13 December 2005 18:13, Henry Barwood wrote:

> I tried to distinguish "hot spots" from "hot pixels", apparently
> unsuccessfully. My samples are petrographic slides that are contaminated
> with particles of alumina polish. The particles luminesce a brilliant,
> bright green, but are of irregular size and dimension. I only want to
> modify the "hot Spots" not the remaining image, hence, I'm reluctant to use
> any other noise reduction or background subtraction filters.
>
> When I remove the hot spots using the threshold technique it leaves a
> completely black spot in place of the bright green spot. I would like to
> replace the removed area with a less conspicuous area that more accurately
> matches the surrounding image. Don't know if I explained that properly, but
> I'm sort of struggling for terminology here!

I wonder if you are using a black foreground on a white background...
Try these versions instead. (They set IJ colours as I have them here).
First macro deletes only single white pixels, the other does the same with
white areas.

Cheers,
Gabriel

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SaturatedSinglePixelDenoising.txt
// G. Landini 16/July/2005
// This macro detects saturated *single* pixels (8 connected) in the
// image (grey=255) and replaces them with the pixel value of
// either the mean or the median of the neighbours (choose which
// method one by  un-commenting the lines indicated below.
// Works with 8bit and 24 bit images only.
// Needs the Particles8 plugin available at:
// http://www.dentistry.bham.ac.uk/landinig/software/software.html

run("Colors...", "foreground=white background=black selection=yellow");
run("Options...", "iterations=1 black count=1");
run("Duplicate...", "title=Denoised");
setBatchMode(true);
run("Duplicate...", "title=pixels");
if (bitDepth==24) run("8-bit");

setThreshold(255, 255);
run("Threshold", "thresholded remaining");

//---
// if you want to denoise small clusters of pixels, rather than single pixels,
// then comment the following 5 lines, but be aware that the average
// or median will not be correct as other pixels in the cluster may
// contribute to the corrected value:
run("Duplicate...", "title=non-single");
run("Particles8 ", "white show=Particles filter minimum=2 maximum=999999
overwrite");
imageCalculator("Subtract", "pixels","non-single");
selectWindow("non-single");
close();
//---

selectWindow("Denoised");
run("Duplicate...", "title=median");

// use average of the 8 neighbours
run("Convolve...", "text1=[1 1 1 1 0 1 1 1 1] normalize");

// use median of the 3x3 neighbourhood
//run("Median...", "radius=1");

if (bitDepth==24){
  selectWindow("pixels");
  run("RGB Color");
}

imageCalculator("AND create", "pixels","median");
imageCalculator("Subtract", "Denoised","pixels");
imageCalculator("Add", "Denoised","Result of pixels");
selectWindow("median");
close();
selectWindow("Result of pixels");
close();
selectWindow("pixels");
close();
setBatchMode(false);


////////////////////////////////////////////////////////////////////////////////////////////
// SaturatedPixelsDenoising.txt
// G. Landini 16/July/2005
// This macro detects saturated  pixels (8 connected) in the
// image (grey=255) and replaces them with the pixel value of
// the mean of the neighbours which are not saturated..
// Works with 8bit images only.
// Needs the BinaryConnectivity plugin available at:
// http://www.dentistry.bham.ac.uk/landinig/software/software.html

run("Colors...", "foreground=white background=black selection=yellow");
run("Options...", "iterations=1 black count=1");
t=getTitle();

if (bitDepth()==24){
  run("RGB Stack");
  setSlice(1);
  denoiser();
  selectWindow("Denoised");
  rename("red");
  selectWindow(t);
  setSlice(2);
  denoiser();
  selectWindow("Denoised");
  rename("green");
  selectWindow(t);
  setSlice(3);
  denoiser();
  selectWindow("Denoised");
  rename("blue");
  run("RGB Merge...", "red=red green=green blue=blue");
  rename("Denoised");
  selectWindow(t);
  run("RGB Color");
}
else {
  if (bitDepth()==8) denoiser();
}

function denoiser () {
  run("Duplicate...", "title=Denoised");
  setBatchMode(true);
  xe=getWidth();
  ye=getHeight();
  cycle=true;

  while (cycle){
    selectWindow("Denoised");  
    run("Duplicate...", "title=pixels");
    setThreshold(255, 255);
    run("Threshold", "thresholded remaining");
    selectWindow("Denoised");
    run("Duplicate...", "title=median");
    // use average of the 8 neighbours
    run("Convolve...", "text1=[1 1 1 1 0 1 1 1 1] normalize");
    imageCalculator("AND create", "pixels","median");
    imageCalculator("Subtract", "Denoised","pixels");
    imageCalculator("Add", "Denoised","Result of pixels");
    selectWindow("median");
    close();
    selectWindow("Result of pixels");
    close();
    selectWindow("pixels");
    run("BinaryConnectivity ", "white");
    cycle=false;

    for (x=0;x<xe;x++){
      for (y=0;y<ye;y++){
        n=getPixel(x,y);
        if (n>1){
          if(n<9){
            selectWindow("Denoised");
            putPixel(x,y,(getPixel(x,y)*8 - ((n-1)*255))/(9-n));
            updateDisplay();
            selectWindow("pixels");
          }
          else cycle=true;
        }
      }
    }
    selectWindow("pixels");
    close();
  }
  setBatchMode(false);
  updateDisplay();
}
//////////////////////////////////////////////////////////////////