Rescaling image contrast: excluding outlier pixel values
Tue, 07/24/2018 - 01:24 am
I am working with some images and need to rescale the contrast on those image for visualisation. If I scale to the min-max for the image, it still appears quite dark because I have a handful of extremely bright pixels in the image. In ImageJ the way around this is a button called Auto which seems to trim the top (and bottom) 0.35% of pixels according to the shape of the image histogram. I have coded something similar in Igor* and it works, but it is slow. I'm wondering if there is a faster way to get these values. Is there a function to specify the 99.65th (or Xth) percentile of an image and use that for the scaling? Maybe a histogram function would work? Any help or other ideas welcome.
* I calculate the Min and Max like this and store them in a wave to then do the rescaling in the calling function. It's slow because I duplicate-redimension-sort for each channel and for each z-position.
Variable rCh,gCh,bCh // index of chunk for each channel. -1 means blank
String rgbList = num2str(rCh) + ";" + num2str(gCh) + ";" + num2str(bCh) + ";"
Variable nZ = DimSize(ImageMat,2)
Make/O/N=(nZ,2,3) minMaxW // rows for z, columns min and max, layers r g b
Variable totalOrigPix = DimSize(ImageMat,0) * DimSize(ImageMat,1)
for(i = 0; i < nZ; i += 1)
for(j = 0; j < 3; j += 1)
chSelect = str2num(StringFromList(j,rgbList))
if(chSelect == -1)
Duplicate/O/FREE/RMD=[i][chSelect] ImageMat, tempW
minMaxW[i][j] = tempW
minMaxW[i][j] = tempW[floor(totalOrigPix-(totalOrigPix * 0.003))] // ImageJ does something like 0.35%