# Thread: Processing steps, what order?

1. ## Re: Processing steps, what order?

Originally Posted by Phil Leigh
Linear stretching involves adding (or subtracting) a constant value to every pixel value. There's no resampling involved.

Lets say you had 3 8-bit pixels, values 1, 5 and 10
A linear stretch might shift those to 21, 25 and 30. As a result the image will appear brighter overall (because the screen gamma correlates to the pixel values) but the contrast/dynamic range will remain unchanged.
I wouldn't call it a 'stretch' in this case, it is more like a linear 'shift'.

Richard

2. ## Re: Processing steps, what order?

Originally Posted by frant
I wouldn't call it a 'stretch' in this case, it is more like a linear 'shift'.

Richard
Yes but unless the absolute relative pixel values are maintained it is not "linear" - it is exponential, hyperbolic, quadratic etc etc.
Here's the killer; a true linear stretch MUST be reversible. A non-linear stretch is NEVER reversible.

3. ## Re: Processing steps, what order?

Originally Posted by Phil Leigh
Yes but unless the absolute relative pixel values are maintained it is not "linear" - it is exponential, hyperbolic, quadratic etc etc.
Here's the killer; a true linear stretch MUST be reversible. A non-linear stretch is NEVER reversible.
Time to get things sorted out. Besides the reference I mentioned earlier I found a nice one for Maxim software addressing exactly our topic (CCD Image Processing Tutorial -- Chapter 4, Maximizing Your Data: Histograms and Stretching).

An image is implemented as a collection of integer pixel values representing the amount of light that hit each pixel. Pixel values are typically 16 bit integers but they could be 32. Let us assume that displays are 8 bits. To display the image we must map the pixel value to a display value. For example if we map 16 bit pixel values to an 8 bit display then we map bins of 256 adjacent pixel values to 1 display value. Let us assume the monochromatic case for simplicity. The pixel and display values of black are 0, the ones of white are 256 and 65536, respectively.

There are 2 types of stretching:

1) Screen stretching. This is about redefining the mapping from pixel values to display values. Whereas the original mapping mapped [0-65536] to [0-256], we will now map [Nlo-Nhi] to [0-256]. In the [Nlo-Nhi] range this is a linear function that maps [0-N1] to 0 (black) and [N2-65536] to 256 (white), and everything in between linearly from black (0) to white (256). It does not alter the pixel value, just the mapping of pixel values to display colors. It can easily be undone because it is just about 2 numbers Nlo and Nhi. This is generally referred to as "linear stretching".

2) Pixel value stretching. This is where we change the actual pixel value using functions. These functions are generally nonlinear because they intend special effects such as preventing blown out cores and stars, but they can also be linear. It changes the pixel values and cannot be undone easily especially if several subsequent mappings. This is the kind of stretching that Phil was referring to.

Hope this helps

4. ## Re: Processing steps, what order?

Yes Henk, that is exactly what I was talking about.

So going back to the original question:

1) You can do a temporary stretch that only affects what you see on the screen but does not change your underlying data - you can do this anytime at any step in the processing
2) the time to do non-reversible stretches that make the image data non-linear is after gradient removal and colour/background calibration, deconvolution (if you need any) and initial noise reduction but before any curves or artistic colour manipulation.

5. ## Re: Processing steps, what order?

A couple points have still been left hanging after the useful discussion so far.

It was stated that there is no such thing as linear stretching. This is incorrect (see below, where I explain what linear stretching is, thereby proving that it exists. :-).

It was stated that linear stretching is shifting all the pixel values by a constant (i.e., adding or subtracting). This is incomplete. Linear stretching is altering pixel values using a (surprise!) linear function. A pixel-value-changing function is linear if and only if it is of the form

NewPixelValue = m*OldPixelValue + b

where 'm' and 'b' are constants. This is just the familiar y = mx + b formula for a straight line (hence the term "linear"). As you can see, a linear function can add, subtract, multiply, or divide (subtraction happens if b is negative; division happens if m is less than 1). In fact, it is the multiplication or division that we're primarily after when we do a linear stretch, whose purpose is to compress or expand the dynamic range of our pixels.

You can do a linear stretch safely at ANY time in the sequence of processing steps, even at the very start. The linear nature of the original data is preserved, so processing steps that require linear data (gradient removal, deconvolution, etc.) will still work fine.

How does this relate to what you should or should not do in Photoshop (or other processing programs)? As follows: if you drag the black point and/or white point markers in "Levels" WITHOUT clipping (i.e., having one of the triangles move "into" the histogram) then it turns out that what Photoshop does is, in fact, linear. However, moving the middle triangle in "Levels" is NOT linear. The type of stretching that's normally done with "Curves" is also not linear.

- Mike

6. ## Re: Processing steps, what order?

Mike I agree, i was only using the addition/subtraction as the simplest possible example of a linear function. The key point is that a linear stretch function is reversible provided no clipping has occurred.
This type of linear stretching is also known as contrast stretching or normalisation.

7. ## Re: Processing steps, what order?

Fully agreee on Phils 6 steps!!!

In my workflow 1) to 6) i only add as 1a) LinearFit to the R and G using B as reference. Because B in my camera is very weak
and all raw images have a strong yellow hue.

Gerald

8. ## Re: Processing steps, what order?

Originally Posted by mostschaedel
Fully agreee on Phils 6 steps!!!

In my workflow 1) to 6) i only add as 1a) LinearFit to the R and G using B as reference. Because B in my camera is very weak
and all raw images have a strong yellow hue.

Gerald
Interesting...Linear Fit is of course a linear stretch as discussed in this thread :-)
Have you tried using LF to boost the blue rather than cutting the red and green?

I use LF a lot to match may Ha and Oiii frames to my RGB frames.
cheers
Phil

9. ## Re: Processing steps, what order?

Phew.............My head hurts think I need a lie down now

10. ## Re: Processing steps, what order?

Originally Posted by Phil Leigh
Yes Henk, that is exactly what I was talking about.

So going back to the original question:

1) You can do a temporary stretch that only affects what you see on the screen but does not change your underlying data - you can do this anytime at any step in the processing
2) the time to do non-reversible stretches that make the image data non-linear is after gradient removal and colour/background calibration, deconvolution (if you need any) and initial noise reduction but before any curves or artistic colour manipulation.
I don't have PixInsight, PS or Maxim but I would think that the screen stretch (what you refer to in 1) will become permanent once you save the image. This of course will depend on the software and the save format. Obviously the display resolution will not be used for saving because then we lose bits. So whatever the underlying quality (number of bits) is will be retained.

In this discussion I still see a lot of confusion about linear stretching as opposed to stretching using linear functions but I will not elaborate on what I posted earlier.

Page 3 of 5 First 12345 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•