Removing noise from -fx minima.r and maxima.r calculations

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
TedBaker
Posts: 44
Joined: 2017-10-10T14:14:55-07:00
Authentication code: 1151

Removing noise from -fx minima.r and maxima.r calculations

Post by TedBaker » 2017-12-26T06:01:50-07:00

Analysing film scans I use the values of -fx minima.r, maxima.r, minima.g, maxima.g etc.

Is there a fast (these are 50mb files or more), way of calculating these values but removing outliers, (which is noise either from the scanning process or scratches on the original)

I am currently using -blur 0x7, before calculating the max and min etc. Looking for ideas? I am only interested in removing the noise around the max and minimum values.

snibgo
Posts: 9581
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Removing noise from -fx minima.r and maxima.r calculations

Post by snibgo » 2017-12-26T07:27:53-07:00

How many pixels wide and high?

The "-blur 0x7" will take time. Supplying a radius will reduce this, eg "-blur 21x7". Faster still, use integral images (see Windowed mean and standard deviation), eg:

Code: Select all

convert in.tiff -process integim -process 'deintegim w 21x21' out.tiff
snibgo's IM pages: im.snibgo.com

TedBaker
Posts: 44
Joined: 2017-10-10T14:14:55-07:00
Authentication code: 1151

Re: Removing noise from -fx minima.r and maxima.r calculations

Post by TedBaker » 2017-12-26T08:27:16-07:00

snibgo wrote:
2017-12-26T07:27:53-07:00
How many pixels wide and high?

The "-blur 0x7" will take time. Supplying a radius will reduce this, eg "-blur 21x7". Faster still, use integral images (see Windowed mean and standard deviation), eg:

Code: Select all

convert in.tiff -process integim -process 'deintegim w 21x21' out.tiff
some scans 3000px others 7000px

Thanks, I have been steadily going through your pages, they are very helpful. I had seen the integim process, which actually inspired my question, for a "-fx" style solution.

I will give integim a whirl

snibgo
Posts: 9581
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Removing noise from -fx minima.r and maxima.r calculations

Post by snibgo » 2017-12-26T08:47:01-07:00

Integim suggests another possibility: it can calculate the mean and standard deviation for a window around each pixel. We can then determine whether the pixel lies within the range (mean plus or minus k*SD), where k is whatever you decide is reasonable, eg 1 or 2 or 3. If it is outside the range, we declare the pixel an outlier, so we replace it by the range limit. Otherwise we leave it alone.

This is a smarter method of removing outliers than simply replacing each pixel with a mean, which is what blur does. However, it adds time and complexity, and may be overkill.

EDIT: I should add, as you may know, "-fx" expressions are re-interpreted at every pixel, so is painfully slow, and unusable for images around 5000x5000 pixels. But it can be a useful prototyping tool.
snibgo's IM pages: im.snibgo.com

Post Reply