PixInsight Forum

PixInsight => General => Topic started by: jase on 2011 November 29 02:50:22

Title: DBE and ABE model
Post by: jase on 2011 November 29 02:50:22
Being away for a couple of months I've not had time for processing any images until now.  After launching PI and receiving several updates, the DBE and ABE model output appears rather coarse.  I don't recall it being like this in previous version (or perhaps I've simply forgotten!  :) ).

The distinct gradient lines are visible in the DBE output image hence I would like to know if there is a configuration parameter that can be changed to resolve this?

Thanks
Title: Re: DBE and ABE model
Post by: Cleon_Wells on 2011 November 29 10:32:53
jase, in Model Parameters (1), increase the Tolerance value to around 1.0 and increase the samples per row to 15 in Sample Generation.
There is an art to these adjustments, so experiment, remember after you change a setting click in another adjustment box  to load the new setting.
Cleon
Title: Re: DBE and ABE model
Post by: jase on 2011 November 29 11:20:29
Thanks for the quick reply Cleon.

I don't believe the issue is sampling based.  I have 20 good samples per row with nothing on bright stars or extended objects.  I hear you though, some experimentation is required.

What mystifies me is that DBE is actually doing the opposite of what it was designed to do as the model doesn't fit the image data - no matter which settings I tweak.  It is as though its operating in 4bit mode only capable of modelling 16 shades compared to a full 16bit or higher.  Due to this, it is actually producing background artefacts as the transition between different areas of luminosity isn't smooth.  The distinct lines shown in the model come through into the output data.

I've attached what I've explained to provide a better understanding.  Also I just reset PI back to defaults - same problem.

version
PixInsight Core 01.07.00.0702 Starbuck (x86_64)
PCL 01.00.96.0377
Copyright (C) 2003-2011 Pleiades Astrophoto

Thanks
Title: Re: DBE and ABE model
Post by: Cleon_Wells on 2011 November 29 13:29:12
jase, I see your problem, I haven't had a problem with DBE on my images. I work with 32bit subs and use DBE on my 32bit linear integrated master.
Cleon
Title: Re: DBE and ABE model
Post by: georg.viehoever on 2011 November 29 13:37:58
Is the image to which you apply DBE in float format? If it is integer, it may cause such issues.
Georg
Title: Re: DBE and ABE model
Post by: RBA on 2011 November 29 15:40:21
Yes, some info about the original image could be helpful. Is that background model an auto-SFTed image? Are you applying it to a linear o non-linear image?

Increasing the number of samples is something that goes along with the particular needs of any given image. IMHO it shouldn't be suggested as a "general tip".

In fact, my "general tip", especially when dealing with gradients, would be trying to keep the number of samples low unless you know exactly why you'd need more (which you might, of course).


Title: Re: DBE and ABE model
Post by: jase on 2011 November 29 16:08:23

Is the image to which you apply DBE in float format? If it is integer, it may cause such issues.
Georg

Thanks for your input Georg.

The image is indeed in integer format, not floating.  Though I'm not certain if that is the root cause.  Opening the 16-bit int file and saving it as 32-bit floating, then opening this and performing DBE again yields the same result.  I have just tried this with other images thinking that there is something wrong specifically with one image, alas it occurs on them all.

Why wouldn't integer format be supported with DBE?

I could swear that this functionality was working as expected prior to the last few major PI updates.

Yes, some info about the original image could be helpful. Is that background model an auto-SFTed image? Are you applying it to a linear o non-linear image?

Increasing the number of samples is something that goes along with the particular needs of any given image. IMHO it shouldn't be suggested as a "general tip".

In fact, my "general tip", especially when dealing with gradients, would be trying to keep the number of samples low unless you know exactly why you'd need more (which you might, of course).

Thanks Rogelio.  Sure.  The original image (or images as it now turns out) are basic 16bit int format.  Whether they are FITS or TIF is irrelevant as the same problem is experienced.  These are unstretched images so to speak.  There is a common element however in that they are being created in ccdstack, though as mentioned am near certain DBE worked fine in the past.  The presented background image is indeed autoSTF'd.

Thanks
Title: Re: DBE and ABE model
Post by: sleshin on 2011 November 29 16:39:22
Jase,

Perhaps you're already doing this, but regards the appearance of the background model with stretching, apply the same autostretch with the STF to the background model as used on the linear image. With the trackview icon enabled on the STF, click on the autostretched linear image to set the values used on this image in the STF. Then, without clicking on the background model, transfer the STF values to the background model image by dragging the new instance icon to the backgd model image. That should give you a smoother backgd model  image.

Steve
Title: Re: DBE and ABE model
Post by: pfile on 2011 November 29 21:12:19
but hang on though, there's posterization evident in his background-subtracted image. my first thought was that the background model was extremely smooth, hence the posterization when applying STF. i think that's what you are getting at, right steve?

Title: Re: DBE and ABE model
Post by: Ginge on 2011 November 29 23:40:18
I see tips posterization regularly when applying auto stf to my images but have attributed it to the heavy stretching of an image with smooth gradients. I haven't seen any artifacts in the background-extracted images that corresponds to the lines in the posterized screen-stretched background image either.

Best regards,
Ginge
Title: Re: DBE and ABE model
Post by: Andres.Pozo on 2011 November 30 01:22:39
The STF uses a less precise transformation than HTF. When applying very large stretches the STF shows posterization but since its is only for the visualization it does not matter. If you apply the same transformation using HTF the results are smooth.

If you drag the triangle of the STF panel to the botton of the HTF panel, the STF parameters are transferred to the HTF.
Title: Re: DBE and ABE model
Post by: jase on 2011 November 30 02:01:20
Thanks guys.  I appreciate the input.  I'm missing the link here though.  STF should not impact the calculations of the background model established by the DBE tool.  They are independent right?

Pfile picked up the key point in that the background model itself is posterized, not just how its being displayed.  This is proven since the posterized model is be applied to the source image and creating the artefacts as seen in the previous post.
Title: Re: DBE and ABE model
Post by: georg.viehoever on 2011 November 30 02:19:56
Hi Jase,

the reason why I suggested to use floats is that floats have a much larger dynamic range than integers. In particular, if the values created for the Background in DBE are very small (i.e. in the order of 1/(2**16) in float terms, or <1000 in integer terms), you get posterization with integers. Floats handle this smoothly because values are scaled by an exponent.

Your are right, STF does not influence the result. But apparently it is less accurate then a full Histogram Transform, presumably to be fast. I have also seen cases where STF cause posterization, but with HistogramTransform everything was fine.

Georg
Title: Re: DBE and ABE model
Post by: jase on 2011 November 30 02:47:11
Thanks for the explanation Georg.  I understand the logic of floats having a larger dynamic range / bit space.  Based on this, would I be correct in making an assessment that the DBE tool does not always work within the bit space bounds of the source image?  If DBE is presented with only 16bit integer data, I would have expected it to be able to work with it.
Title: Re: DBE and ABE model
Post by: pfile on 2011 November 30 08:17:01
Thanks guys.  I appreciate the input.  I'm missing the link here though.  STF should not impact the calculations of the background model established by the DBE tool.  They are independent right?

Pfile picked up the key point in that the background model itself is posterized, not just how its being displayed.  This is proven since the posterized model is be applied to the source image and creating the artefacts as seen in the previous post.

oh, but now i understand what steve was trying to say - STF is what's posterizing the data in the DBE result. the suggestion was to try applying the STF as a histogram transformation and see if the posterization goes away.
Title: Re: DBE and ABE model
Post by: Harry page on 2011 November 30 13:49:26
Hi

I have only seen this on jpeg images that I was trying DBE on ,

Is there any way you could let us see the image in question , or you can upload it to my FTP server if you desire to of course  ;)

Harry
Title: Re: DBE and ABE model
Post by: jase on 2011 November 30 18:09:39
Following suggestions here;
Performing an STF to HistogramTransformation does smooth out the model but as others have highlighted, this is ultimately a visual guide.  In both cases the DBE output continues to have posterization.  I'm not proficient enough to push PI for on this as it may well be something I'm doing differently.  My requirement is to operate DBE on unstretched/linear integer data.  This has worked in the past.

More than happy to share the data as this was only a 'fill in' data set I shot while waiting for the main imaging run targets to rise (the fill in is nothing special!). It is of the PGC galaxies surrounding NGC1365.  It is a 96Mb 16bit tiff (integer - no compression) zipped to around 30Mb.  This is the combine RGB data.  Have not got to the luminance as yet.

http://cosmicphotos.com/reprocessed/NGC1365surrounds.zip
File will only be available for a short period of time.

I would certainly like to know if you experience similar challenges with the data.  If not, what did you do to address it?
From my perspective, this is easily reproduced.
Open the tiff in PI
autoSTF it so you can see whats going on
Launch DBE and place samples as needed
apply
autoSTF the model - eekkk looks scary
autoSTF the DBE output - ekkk even scarier...
Title: Re: DBE and ABE model
Post by: jase on 2011 November 30 19:46:26
I should also highlight that if I take the approach;

Open tiff in PI
Launch DBE and place samples as needed (rather difficult to visually see whats going on as no STF applied)
Apply DBE
Save the DBEoutput as a tiff
Open in Photoshop, start stretching with curves etc...

Posterization still exists in the DBE output image!!!  Confirms STF has nothing to do with it.
Title: Re: DBE and ABE model
Post by: pfile on 2011 November 30 20:23:37
it's not that the STF is causing it, it's that the STF histogram transform may end up posterizing certain data. but of course since it's just a screen stretch, it's not actually changing anything.

later tonight i'll try that image and see what happens.

just a hint, while working on the STF'd image, you can drag the DBE triangle to the desktop, thereby creating a process icon. you can drag this icon to another image of the same dimensions and it will execute the DBE. no need to redo the samples on an unstretched/un-STF'd image.


Title: Re: DBE and ABE model
Post by: jase on 2011 November 30 21:29:53
...but of course since it's just a screen stretch, it's not actually changing anything.

Agreed. Thats the logic I'm working with.  Though the DBEoutput image defies this!  I seriously hope its just something I'm doing wrong but am beginning to doubt it is.  In review of previously created astro images, I can confirm I've successfully been able to achieve the task before.
Title: Re: DBE and ABE model
Post by: pfile on 2011 November 30 22:41:51
i don't really know why this is happening. the values in the extracted background are very, very small (0.0014 to 0.0016) and so perhaps subtracting such small numbers and converting back to i16 yields posterization.

at any rate, if i explicitly change the sample format to f32, everything works as expected.

after you load the tiff image, open the SampleFormatConversion process and convert the sample format to f32. doing the DBE on the f32 version gives the expected result - no posterization. the STF on the background model is still posterized but as steve suggested if you actually apply the STF autohistogram to the HistogramTransformation tool and apply that to the background image, you will see that it is smooth.

i think you tried to do this by saving as a f32 file and reopening it, but somehow this does not work, i guess.



Title: Re: DBE and ABE model
Post by: jase on 2011 December 01 00:53:37
Converting from i16 to f32 format, then performing DBE didn't work for me, Pfile.  I get the same result. I double checked that the file converted correctly, which it did given the fits header now listed 32bit. To ensure it had nothing to do with STF, after performing the DBE operation of the f32 file, I saved it back into i16 and loaded it into photoshop.  The attached image shows the result after a few non linear stretches - reminds me of an onion diagram!
Title: Re: DBE and ABE model
Post by: Juan Conejero on 2011 December 01 00:59:28
Hi Jase,

What you're seeing is normal. A background model image is an extremely smooth function that usually requires a 32-bit format to be represented correctly. For this reason the DBE tool generates background models as 32-bit floating point images by default.

A screen transfer function in PixInsight is a 16-bit histogram transformation applied to generate the screen rendition of the image, which only has 8 bits per color channel. Clearly there is *no way* you can see a DBE model without posterization on the screen. Some models will exhibit more posterization than others, and some will look really ugly, depending on their complexity and on the smoothness of the sky gradients represented. The 16-bit histogram resolution is becoming a problem in PixInsight for screen renditions, especially as we do more and more HDR work (where we sometimes have to work with 32-bit integer or 64-bit floating point images). In a future version of PixInsight histograms will be generated with 20-bit resolution as an option (1048576 levels, or 16 times more levels than a 16-bit histogram).

The DBE model has no posterization at all. It is a linear 32-bit floating point image where finding 10^6 distinct discrete values is not unusual. You can verify this easily:

- Click the little blue triangle in the bottom bar of PI's main window and select Normalized Real Range > 1e-07. Now you are getting real pixel readouts with seven decimal digits.

- Open the ScreenTransferFunction tool and select the DBE model image.  Apply an automatic stretch or, much better, adjust STF manually (the statistic properties of DBE models are not very well suited for the automatic screen stretch function).

- Now zoom the image 10:1 or more. Identify the posterization steps. They are large regions of the image on the screen with constant color. Actually, they are not constant at all in the model image: click on the image and move the cursor over one of these posterized areas, watching the pixel readout values. They change rapidly as you move the cursor.

If you are still not convinced, I can tell you how to compute the total number of discrete pixel values in a floating point image with a script in PixInsight.

Quote
Open in Photoshop, start stretching with curves etc...

In the case of that application, posterization will not only happen on the screen rendition of the image; that application is unable to work with linear data and clearly inappropriate to handle floating point images.
Title: Re: DBE and ABE model
Post by: Juan Conejero on 2011 December 01 01:21:51
Jase,

I've made a quick&dirty test with your image and there is no posterization at all:

http://forum-images.pixinsight.com/20111201/DBE/01.jpg

Of course, the image has to be converted to 32-bit floating point format before subtracting the DBE model. This operation cannot be performed in 16-bit format because the model has variations in the 1e-7 range; that's why you're getting posterization.

In fact, this DBE model should be generated in 32-bit integer or 64-bit floating point format; it is clearly exceeding the range of 32-bit floating point. You can select the output sample format in the DBE tool, in the Model Image section. Note that if you apply the target image correction with DBE (instead of doing it separately with PixelMath, as in my example) converting the image to a 32-bit format *before* using DBE is mandatory.

Isn't this example a nice demonstration that 16 bits are not sufficient in astrophotography? Even 32-bit floating point is not enough in some tasks :)

Hope this helps.
Title: Re: DBE and ABE model
Post by: jase on 2011 December 01 01:37:04
Juan,

Thank you very much.  Your clear and concise explanation of the model logic makes sense.  I followed your steps and agree the model is correct.  Using the histogram transform function also confirms this by getting around the shortfalls of STF operation in a 16bit space (as initially advised by Steve)  This has helped immensely.  I believe I'm now heading the right direction again.

Thanks
Title: Re: DBE and ABE model
Post by: Andres.Pozo on 2011 December 01 01:46:22
I would certainly like to know if you experience similar challenges with the data.  If not, what did you do to address it?
From my perspective, this is easily reproduced.
Open the tiff in PI
autoSTF it so you can see whats going on
Launch DBE and place samples as needed
apply
autoSTF the model - eekkk looks scary
autoSTF the DBE output - ekkk even scarier...

The first thing that you have to do BEFORE applying the DBE is to convert the image from int16 to float32. The int16 format has not enough precision in the dark part of the histogram for this kind of transformations. Applying a DBE on your image after converting it to 32bits renders a posterization-free image:
Title: Re: DBE and ABE model
Post by: jase on 2011 December 01 01:54:31
Thanks Andres.  How would one go about converting it back down to i16 and still maintain the correct background? Pixelmath?  SampleFormatConversion appears to get me straight back to the start with posterization present.
Title: Re: DBE and ABE model
Post by: Juan Conejero on 2011 December 01 02:19:11
Quote
How would one go about converting it back down to i16 and still maintain the correct background?

You cannot, unless you stretch the image. The linear image after background model subtraction requires much more than 2^16 discrete values. Once you have stretched the image with HistogramTransformation, a better redistribution of values over the available dynamic range will allow you to re-quantize the image with 16-bit resolution without *visible* posterization.

However, I don't recommend you do so. Much better if you continue all of your post-processing in 32-bit format and convert to 8-bit format a duplicate of the final image for web deployment.
Title: Re: DBE and ABE model
Post by: jase on 2011 December 01 02:52:44
Thanks Juan.  I tried this shortly after raising the question and it worked.  Was just wondering if there was an alternative.  I appreciate where you are coming from in keeping post processing in 32bit format.  Whilst still learning the PixInsight ropes, I'll need to convert and exchange between other processing apps.
Title: Re: DBE and ABE model
Post by: pfile on 2011 December 01 08:01:13
trust me, eventually you'll stop using those other apps  O0