Author Topic: grayscale batch conversion  (Read 14665 times)

astropixel

  • Guest
grayscale batch conversion
« on: 2010 September 02 17:58:48 »
Hi. I want to convert 20+ calibrated files to grayscale for debayering. Is there a command line option for batch conversion that I could use, or is there an alternative method. I have looked around before asking the question, but cant anything conclusive.

Muchos gracias.




Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: grayscale batch conversion
« Reply #1 on: 2010 September 02 18:04:35 »
I don't understand why you'd convert a color image to grayscale so you can debayer but if you're positive that's what you need to do then create an image container, add your images and applying the greyscale conversion. Just tried it and it works.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: grayscale batch conversion
« Reply #2 on: 2010 September 02 18:24:41 »
I've got the impression that Sander's suggestion wouldn't work. If I'm not wrong, you opened the CRW files as color images, but without debayering (i.e. each channel has its own information, and filled with zeros). In that case you should extract the V channel (I think that PixelMath has a function to call the HSV-V channel. So, you should make a PixelMath instance that replaces all the channels with the V value, and then do the grayscale conversion; create a process container with both processes, and apply that to a image container with your files).
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: grayscale batch conversion
« Reply #3 on: 2010 September 02 18:52:42 »
I think the question was 'how do I convert a set of images from RGB to grayscale' but maybe I didn't understand. In any case, what I suggested doesn't work and indicates I don't understand the image container. Luckily I never use it :)

When I add 2 images, have it selected and then do 'convert to grayscale' only 1 image gets converted. This is because I can't drop a ConvertToGrayscale process onto an image container.

Sorry, I don't know how to do what you're asking for.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Philip de Louraille

  • PixInsight Addict
  • ***
  • Posts: 289
Re: grayscale batch conversion
« Reply #4 on: 2010 September 02 19:42:23 »
I am slightly confused at the request. A bayered dataset is in a greyscale format. At least, it appears to be so whenever I open such images. You debayer it to get color. And then, perhaps you'd want to extract the L channel? (Basically summing the 3 color channels onto one image?) I may have my terminology wrong here...
Philip de Louraille

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: grayscale batch conversion
« Reply #5 on: 2010 September 02 19:55:42 »
No Sander, the problem is not at the image container :D
As I understood, he opened the crw data as a RGB image, not debayered. This means, channel data has been split into the respective channel, but no interpolation is done to fill the missing pixels. It is an option on the CRW format preferences.
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: grayscale batch conversion
« Reply #6 on: 2010 September 02 21:39:45 »
Hi,

I recommend converting your RGB un-debayered files to grayscale before calibrating. Still there has to be a better way to load your RAW files while keeping them grayscale.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

astropixel

  • Guest
Re: grayscale batch conversion
« Reply #7 on: 2010 September 02 22:07:16 »
It seems that my understanding of the discussions about RAW processing is erroneous. I was of the understanding that the CFA image option was not desirable, unless one only wants a monochrome image. From what I can see that is not the case. My apologies Sander, the option is there all along.

It's all very new and quite a challenge, just as well I have time this week. Many thanks again.

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: grayscale batch conversion
« Reply #8 on: 2010 September 02 22:10:13 »
I never work with DSLR/RAW files so that part is new to me too :)

If all you want to do is stack a bunch of DSLR images and you have a PC you may want to give DeepSkyStacker a try. It does everything automatically. Once you get a handle on how things work you can move all or part of the stacking process to PI. Naturally you'd still use PI to process. That's what I do. Stack in DSS, process in PI.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Enzo De Bernardini

  • PTeam Member
  • PixInsight Addict
  • ***
  • Posts: 274
  • Resistance is futile.
    • Astronomí­a Sur
Re: grayscale batch conversion
« Reply #9 on: 2010 September 02 22:46:04 »
When I add 2 images, have it selected and then do 'convert to grayscale' only 1 image gets converted. This is because I can't drop a ConvertToGrayscale process onto an image container.

Maybe my language skills are insufficient and I do not quite understand, but I think it works: if you make a ImageContainer icon (with the input images, and fields filled) and drag and drop a ConvertToGrayscale process over them, all images are converted and saved in the output directory. This works with many other processes, of course.

Maybe I'm missing something  :-[

Regards,

Enzo.

astropixel

  • Guest
Re: grayscale batch conversion
« Reply #10 on: 2010 September 03 00:14:32 »
I'll look into these options. Many thanks, once again!

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: grayscale batch conversion
« Reply #11 on: 2010 September 03 00:41:08 »
Hi,

Wow, what a mess we have here :)

Just let me prepare a few screenshots and I'll show you how to carry out this task very easily with PixelMath, Debayer and an ImageContainer. Come back in a while!
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

astropixel

  • Guest
Re: grayscale batch conversion
« Reply #12 on: 2010 September 03 02:36:58 »
OK - found it again - this is what I'm referring to -

Quote
"After ImageCalibration, you must de-Bayer the images. This can be done with the excellent BatchDeBayer script by Ken Pendlebury which invokes the also excellent Debayer tool written by Sander Pool. Once you have de-Bayered the images, you can register them with StarAlignment and integrate the registered images with ImageIntegration." Juan Conjero

If the Create RAW Debayer Image is selected the output is RGB. Hence the need to convert to gray scale before debayering.

I tried the Create RAW Debayer CFA Image, but there was considerable checkerboard or lattice/mazing depending on the image set. The most reliable end product appears to be with the settings described -
http://pixinsight.com/forum/index.php?topic=2118.msg13737#msg13737

Question - Does it matter that the master bias dark and flats have been calibrated with different settings to the lights; e.g., bias, darks and flats integrated with dslr_raw default/factory settings, but lights processed with the recommended settings - does dark scaling take care of this?

Muchos gracias

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: grayscale batch conversion
« Reply #13 on: 2010 September 03 03:58:20 »
Hi again,

Quote
If the Create RAW Debayer Image is selected the output is RGB. Hence the need to convert to gray scale before debayering.

Exactly. I'll show you how this task can be accomplished easily in PixInsight. First I'll explain how to perform the conversion/debayering process manually. Then I'll show an automatic solution.

We start with a RGB Bayer image. This is actually a raw CFA image, but each color filter element has been stored as a separate plane, instead of a single monochrome plane. In a RGB Bayer image each raw pixel is stored as a 2x2x3 cube: one red sample, two green samples and one blue sample stored in three separate rows. The nonexistent elements (8 in total) are set to black. This is how a RGB Bayer image looks like:


Loading DSLR CFA images as RGB Bayer images has some advantages for image calibration: our ImageCalibration tool is able to detect the Bayer pattern automatically in a RGB image, and it can compute dark scaling factors more accurately on a per-channel basis. The disadvantage is that the calibrated image files occupy three times more space on disk. To calibrate DSLR raw images as RGB Bayer images in PixInsight, you must set the following preferences for the DSLR_RAW format:


Note that you can also select the Create RAW Bayer CFA image option, in which case the RGB-to-CFA conversion that I'm about to describe isn't necessary because you work with CFAs directly.

Before continuing, you've been told that you can use another application(s) to calibrate and stack your images in a more automatic fashion. That's true, and there are good applications out there. However, the recommended applications, even doing a nice work, can't rival PixInsight's ImageCalibration tool for automatic dark scaling (with total independence of temperatures and exposure times), StarAlignment for accurate image registration, and the sophisticated stacking and pixel rejection algorithms implemented in our ImageIntegration tool. This is just my opinion, and it is obvious that I am biased. Now let's continue.

So we have calibrated a set of images, and they have been written as RGB Bayer FITS image files by the ImageCalibration tool. The next step is debayering them, so we can align them with the StarAlignment tool. The problem is that the Debayer tool requires a monochrome CFA image to work; it doesn't accept RGB Bayer images. So we need to regenerate the original CFA prior to debayering. This task is very easy to do with PixelMath, as the following screenshot demonstrates.


The PixelMath expression computes the maximum of the R, G and B channels:

max( $T[0], $T[1], $T[2] )

Important: note the disabled Rescale result option on PixelMath.

The above PixelMath instance replaces the original RGB image. This is not what we want, because Debayer requires a grayscale image. So we must tell PixelMath to send its result to a new grayscale image:


and finally we can apply the Debayer tool:


Obviously, doing this work manually is a tedious task if we have many images. One would think that ImageContainer and ProcessContainer can be used to implement this as a batch process. However, this is not possible in this case because the PixelMath result generates a new image, which is not supported (for now, this will change in a future version) by ImageContainer.

So the solution is a script. I have modified Ken Pendlebury's BatchDebayer script to implement this conversion. The whole task is carried out automatically; the script detects a RGB Bayer image and performs the required steps in a completely transparent way, so you only have to select your calibrated images, select an output directory, and click OK. I'm going to post the modified script on the New Scripts and Modules board in a few minutes.

Hope this provides useful information to all DSLR users.
« Last Edit: 2010 September 03 04:04:32 by Juan Conejero »
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

astropixel

  • Guest
Re: grayscale batch conversion
« Reply #14 on: 2010 September 03 14:36:04 »
Juan. Many thanks for the time you've devoted to this. The modified debayer script is just what's needed for DSLR users, and it works beautifully - tried it out on CR2 and fit files - excellent - simplifies the workflow with great results.

Also, would you mind if I compiled this and the information from other posts (linked and referenced), just to consolidate the information in one place? Or at the very least, create a sticky that links to all the relevant posts.
« Last Edit: 2010 September 03 19:25:12 by astropixel »