Author Topic: True Colors  (Read 24909 times)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: True Colors
« Reply #30 on: 2010 March 20 17:29:29 »
Niall,
...
Basically, I think all the work that has gone in here really helps to confirm one thing - there is no 'one way' to do things. Different areas of any image will need to be treated with a different approach. ...

I guess you are right. No one recipee will work for all situations. In the process of this investigation, I learned a lot about colors, HistogramTransforms, ChannelExtraction/Combination and some basics about color spaces. The important bit is that you need to be aware of the specific properties of the different transforms. The essence of what I learned is this:

- The HistogramTransform is probably close to what you intuitively expect: bright objects become white. This gives a certain additional dynamic contrast to the images. In some cases you are able to restore some of the color using saturation boosts, but not always. The same is true for pusing I from HSI.
- Pushing L (from CIE LAB) instead of using a Histogram transform is a bad idea for the dim parts of the picture. They loose their color.
- Pushing V (from HSV, "V-Transform") preserves much of the color. It is probably a good approach if the focus of the image processing is to preserve color for both bright and dim parts. But also looses some contrast in the bright parts of the picture (because it cannot make things brighter by making them whiter, as the HistogramTransform can).
- I did not find a way to push brightness of astronomical images while preserving color 100%. V-Transform is close, but not perfect (please also note my previous post today, http://pixinsight.com/forum/index.php?topic=1689.msg10371#msg10371).

Kind regards,

Georg
« Last Edit: 2010 March 20 17:39:59 by georg.viehoever »
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: True Colors
« Reply #31 on: 2012 December 23 02:53:03 »
Hi folks,

I'm not sure if I should be resurrecting an old thread but as it speaks directly to my topic I'll risk it for my first post. Having become interested in "true colours" I first went down the PixelMath route of extracting three "saturation" images from an RGB using RGB[n] / max(RGB[0] + RGB[1] + RGB[2], 0.000001) for n = 0, 1 and 2. I then stretched a "luminance" image derived using (RGB[0] + RGB[1] + RGB[2]) and then finally used PixelMath to produce an RGB by multiplying the stretched luminance by each "saturation" image for red, green and blue. Mathematically it preserves the ratios of red, green and blue in the stretched result but it does require a deal of care regarding the black clipping point. Then somebody suggested using HSV and that is how I came to this thread.

I'm using some M42 data which, due to the rotten UK weather, is still woefully short of where I want it to be in terms of depth but should serve for the purpose at hand. Here are the results of a regular MaskedStretch (script) plus a light Histogram stretch of an RGB on the left and a similar procedure using the same MaskedStretch script settings on the V component on the right. I didn't let the final Histogram stretch of the V image go so far as with the RGB.



As was noted earlier in the thread the colour of the "V-stretch" image is much better preserved in the bright areas but visually there's a lack of contrast. On a whim I added the two images together in equal proportions and rescaled.



Is this the best of both worlds or best avoided? The result above has had minimal post-processing in Photoshop after the two stretched images were added (just some clean-up and clipping) as the point was not to demonstrate my PS skills, or lack thereof. There is scope for variation in the degree to which the "V-stretch" is performed and the proportions of the blend of the two stretched images so there is room for artistic discretion as desired. Probably not many images where this might be useful but I think it has helped restore some of the colour to the brightest portions while retaining contrast.

Bob.

« Last Edit: 2012 December 23 03:09:27 by Bob Andersson »
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: True Colors
« Reply #32 on: 2012 December 23 09:16:10 »
Hi folks,

Following on, here's a comparison of the results of a single histogram stretch, a stretch of the V component of an HSV separation when combined with the unstretched H and S components and the result of adding the two.



The first column of stars represents where I was aiming to get back to. I selected three star colours, spectral types B, G and M, and additionally for each I've blown the cores a little bit and quite a bit, as noted in the row titles. The three colours were produced by taking a monochrome "star" (actually a software creation) and reducing the gain of the R, G and B components as necessary to get the required colour. The slightly blown and blown stars were produced by a combination of an exposure boost and clipping. To get something that needed stretching I just reduced the intensity of red, green and blue at every pixel by a factor of one hundred.

The second column shows the result of a single histogram stretch, performed by eye on the entire column and with a view to getting back somewhere near the unblown stars in the first column. Not bad but even so there is already a degree of colour loss in the cores of those unblown stars and that gets significantly worse as the stars get more blown.

In the third column the "V-stretch" has gone over the top so far as the colours of the cores of the unblown stars are concerned. For the blown stars the V-stretch has done a better job of holding on to the correct colour until the blown area is reached at which point there is an ugly discontinuity.

The fourth column is just the result of adding the results in columns two and three together in equal proportions. I'd suggest that the result is actually pretty good for the unblown stars, arguably better than either the regular or "V" histogram stretches. Still not pretty if the star cores are blown.

The final two columns, Hue and Saturation, were included to show where that discontinuity in the "V-stretch" originates. It would seem that the algorithm used to separate out the H, S and V components does a remarkably good job of holding on to the colour and then suddenly gives up! I can also offer those two columns as proof that the colour in the original unblown "star" images was actually uniform and not, as the eye might suggest, already washing out in the cores of even the unblown trio. By the way, one can see that there was actually a much fainter "star" present in the original test image but it was so faint that it didn't intrude, even after any of the luminosity stretches.

My conclusion, and this probably comes as no surprise, is that no stretch is perfect even when operating with unblown data. If one could be sure that nothing in an image was blown then possibly the result of adding the regular and "V" stretches gets closest to recovering the original but how often is one dealing with an image where a goodly number of stars are not blown!

One final thought: if one could perform an HSV separation tuned for astrophotography where detection of blown areas in the cores of the bright stars could be used to smooth or even eradicate those discontinuities in the H and S separations one might be onto a winner!

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: True Colors
« Reply #33 on: 2012 December 23 11:12:43 »
Interesting research! If I understand correctly some combination of original data+V-stretch is not bad if there are no blown out areas. I have to admit though that I dont have a solution for the discontinuities caused by overexposed cores. Ideas how to handle that are welcome! (Of course it could be handled by observational techniques such as HDR, but blown out stars are in almost any image....)
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 988
    • http://www.astrofoto.es/
Re: True Colors
« Reply #34 on: 2012 December 23 12:15:36 »
Hi Bob,

I would suggest you to read my article Dynamic Range and Local Contrast. I talk about this topic in the section "High-contrast, small-scale structures".


HTH,
Vicent.

Offline marekc

  • PixInsight Addict
  • ***
  • Posts: 177
Re: True Colors
« Reply #35 on: 2012 December 23 21:58:30 »
I hope I'm not hijacking this thread, but since Vicent has mentioned his `Dynamic Range and Local Contrast' article, I thought I'd take this opportunity to re-ask a question about that article.

About a year ago, I was trying to follow along with Vicent's article, and I ran into some things I didn't understand. Vicent, if you happen to have the time to look at these questions, could you help me understand how the PixelMath expressions are applied to certain images?

Here are the detailed questions:

http://pixinsight.com/forum/index.php?topic=3423.msg25415#msg25415

Thanks, and I understand if you don't have time... everyone is very busy this time of year, and especially with `Ripley' coming out!

- Marek

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: True Colors
« Reply #36 on: 2012 December 24 01:40:27 »
Hi Vicent,

Thanks for the suggestion. I've read your article a few times since I got PI and it served as a useful pointer to the MaskedStretch script which is currently my default method when I start a stretch.

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: True Colors
« Reply #37 on: 2012 December 24 03:08:40 »
Hi folks,

At the end of my last substantive post I wrote:

Quote
One final thought: if one could perform an HSV separation tuned for astrophotography where detection of blown areas in the cores of the bright stars could be used to smooth or even eradicate those discontinuities in the H and S separations one might be onto a winner!

Just to finish off that thought here's the result of a manual clean-up of the H and S files using Photoshop to copy adjacent pixels to paste over the blown cores:



The blown cores are still visible in the V-stretch but that ugly discontinuity has gone and the result of adding the regular and cleaned V-stretch images together looks even better to my eye. By the way, I usually use the MaskedStretch script to do an initial stretch and that was what I used in the post above with M42 but for some reason MaskedStretch didn't get on with my test image (appeared to hang) so I just used the HistogramStretch tool for this test.

I don't believe it is reasonable to try to "clean" blown areas in a luminance image but I think tidying up the areas in the H and S components of an HSV separation where red green or blue pixels in the source RGB hit, say, 0.95 (could be a slider controlled parameter) is fair game and could potentially be automated so long as it is only stars that have blown and not nebulosity. Extract a map of blown areas, use that to target pixels in the H and S images that need replacing and replace such pixels so that there's a smooth gradient.

I used to program in C++ but it's been a few years and I never did anything serious with JavaScript. Maybe I should make that my New Year's resolution but if someone gets there ahead of me I wouldn't mind at all. All I want is a tool to do an HSV separation using the PI routine and which then uses the source RGB to inform the cleaning of the H and S component images. Any takers?  :)

Bob.
« Last Edit: 2012 December 24 03:25:38 by Bob Andersson »
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Re: True Colors
« Reply #38 on: 2013 January 08 12:00:20 »
Hi folks,

It's been very quiet on the observational front but some nasty noises have been emanating from my little corner of the Cotswolds. Yes, I've been thinking again...

Actually, I've been dipping a toe into Javascript programming for the first time with a view to writing a PixInsight script to "repair" the H and Sv components of an HSV separation. Today I got to the point of needing to know how HSV is derived from RGB so that I could better understand how the hue and saturation (H and S) values could be "fixed" where the source RGB was tending towards saturation. With apologies to the non-programmers reading this here are the relevant code snippets for conversion between RGB and HSV (Source):

Code: [Select]
/**
 * Converts an RGB color value to HSV. Conversion formula
 * adapted from http://en.wikipedia.org/wiki/HSV_color_space.
 * Assumes r, g, and b are contained in the set [0, 255] and
 * returns h, s, and v in the set [0, 1].
 *
 * @param   Number  r       The red color value
 * @param   Number  g       The green color value
 * @param   Number  b       The blue color value
 * @return  Array           The HSV representation
 */
function rgbToHsv(r, g, b){
    r = r/255, g = g/255, b = b/255;
    var max = Math.max(r, g, b), min = Math.min(r, g, b);
    var h, s, v = max;

    var d = max - min;
    s = max == 0 ? 0 : d / max;

    if(max == min){
        h = 0; // achromatic
    }else{
        switch(max){
            case r: h = (g - b) / d + (g < b ? 6 : 0); break;
            case g: h = (b - r) / d + 2; break;
            case b: h = (r - g) / d + 4; break;
        }
        h /= 6;
    }

    return [h, s, v];
}

/**
 * Converts an HSV color value to RGB. Conversion formula
 * adapted from http://en.wikipedia.org/wiki/HSV_color_space.
 * Assumes h, s, and v are contained in the set [0, 1] and
 * returns r, g, and b in the set [0, 255].
 *
 * @param   Number  h       The hue
 * @param   Number  s       The saturation
 * @param   Number  v       The value
 * @return  Array           The RGB representation
 */
function hsvToRgb(h, s, v){
    var r, g, b;

    var i = Math.floor(h * 6);
    var f = h * 6 - i;
    var p = v * (1 - s);
    var q = v * (1 - f * s);
    var t = v * (1 - (1 - f) * s);

    switch(i % 6){
        case 0: r = v, g = t, b = p; break;
        case 1: r = q, g = v, b = p; break;
        case 2: r = p, g = v, b = t; break;
        case 3: r = p, g = q, b = v; break;
        case 4: r = t, g = p, b = v; break;
        case 5: r = v, g = p, b = q; break;
    }

    return [r * 255, g * 255, b * 255];
}

At first glance this looks bizarre but plugging some numbers in does demonstrate, if demonstration were needed, that one can recover the original RGB values after conversion to and from HSV. But the definition of V (the channel to be stretched) as the maximum of any of red, green or blue looks, at first glance, as though it might be a problem when stretching even though the ratio of R to G to B remains unchanged for any given pixel.

If one stretches an RGB image the non-linear shape of the curve causes an amplification of colour differences in the faint bits and a diminution of colour differences in the bright bits, the latter resulting in the familiar loss of colour in the bright stars and bright nebulosity. While stretching the V component of an HSV separation results in immunity from such colour shifts it occurs to me that there is a potential issue simply because V is defined as whichever is the greater of a pixel's values of red, green or blue.

An example might help so consider three pixels where, one with RGB = (200, 0, 0), one with RGB = (66, 67, 67) and one with RGB = (200, 200, 200) - I've used 8-bit values here just to make it easier to read. The first two might be appear similar in "brightness" (the experts could no doubt refine the numbers) but however you cut it the last one will be lot brighter. That said the V components are, respectively, 200, 67 and 200 for the three pixels. As a result, if I've got my best thinking head on this evening, the application of a (non-linear) stretch of a V image will result in changes in relative luminosity where there are large differences in saturation. OK, the values I used don't need a stretch but the principle stands.

Does this matter? In a search for perfection I'd say "Yes" but that begs the question of how one defines perfection. Arguably the formula I described in this post uses a more natural definition of luminance, even if using the sum of red, green and blue might have the experts clutching their heads in despair, and it does retain the precise ratios between red, green and blue at every pixel. Hmm, more thinking required...

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: True Colors
« Reply #39 on: 2013 January 08 12:22:51 »
Would this http://en.wikipedia.org/wiki/HSL_and_HSV#Lightness give you some ideas?
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)