snibgo's ImageMagick pages


In most digital cameras, each sensor element records either red or green or blue. These are arranged in a mosaic. A critical part of processing raw camera images is "demosaicing", which amounts to guessing suitable values for the other two channels at each pixel.

I use dcraw for this, as it does a good job. However, we can get the raw mosaic values from dcraw, and demosaic with ImageMagick. This will use a simpler algorithm than dcraw, giving lower quality, but it gives a glimpse under the hood.

The method given here processes each of the four channels (R, G0, G1 and B) independently. This is a weakness, and makes it more likely to generate false colours at edges than algorithms that assume colour correlation between pixels.

See also:

For the simpler inverse process, making a Bayer image from a normal colour image, see my Mosaicing page.


On Windows, dcraw.exe is installed in the ImageMagick directory. Otherwise, download dcraw.c from Dave Coffin's website and compile.

Sample image

I took a photo of a red car and a blue car, with green grass between them. The camera, a Nikon D800, recorded a .jpeg and a .nef file. Here is the jpeg reduced, and three crops greatly enlarged.

set WEB_SIZE=-resize 600x600

set CAMERA_SRC=\pictures\20130713\AGA_1369

%IM%convert %CAMERA_SRC%.jpg ^
  -write info: ^
  ( +clone %WEB_SIZE% -write dm_j_cars.jpg +delete ) ^
  ( +clone -crop 8x8+1200+2000 +repage -write dm_j_red_car.png +delete ) ^
  ( +clone -crop 8x8+2400+4300 +repage -write dm_j_green_grass.png +delete ) ^
  ( +clone -crop 8x8+6400+1500 +repage -write dm_j_blue_car.png +delete ) ^
\pictures\20130713\AGA_1369.jpg JPEG 7360x4912 7360x4912+0+0 8-bit sRGB 16.37MB 0.609u 0:00.609
set bpText=Red car
call %PICTBAT%blockPix dm_j_red_car.png
set bpText=Green grass
call %PICTBAT%blockPix dm_j_green_grass.png
set bpText=Blue car
call %PICTBAT%blockPix dm_j_blue_car.png
set bpText=

call %PICTBAT%mHist %CAMERA_SRC%.jpg
copy /y %CAMERA_SRC%_hist.png dm_j_cars_hist.png

All the histograms on this page are of the full image, not of the web-size JPEG.

dm_j_cars.jpg dm_j_red_car_bp.png dm_j_green_grass_bp.png dm_j_blue_car_bp.png dm_j_cars_hist.png
call %PICTBAT%stats %CAMERA_SRC%.jpg 

set jpegSD=%statSD%
min=0    max=1    mean=0.439138    SD=0.241773
satMin=0 satMax=1 satMean=0.226577 satSD=0.201505

The in-camera processing has clipped highlights.

Conventional processing with dcraw

In normal use, we can tell dcraw to demosaic, and use the camera's white balance ("-w", lower-case w), and create an sRGB output.

%IM%dcraw -v -o 1 -6 -w -T -O dm_cars_dcr.tiff %CAMERA_SRC%.nef 
Loading Nikon D800 image from \pictures\20130713\AGA_1369.nef ...
Platform 0: Intel(R) Corporation OpenCL 1.2 
	Device 0: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
	Device 1: Intel(R) HD Graphics 4600  <---
Scaling with darkness 0, saturation 16383, and
multipliers 1.933594 1.000000 1.394531 1.000000
AHD interpolation (CL)...
Converting to sRGB colorspace...
Writing data to dm_cars_dcr.tiff ...

ImageMagick will complain about some metadata tags.

identify.exe: ASCII value for tag "Artist" contains null byte in value;

value incorrectly truncated during reading due to implementation limitations.
`TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/850.

We can tidy these up:

exiftool -tagsfromfile dm_cars_dcr.tiff dm_cars_dcr.tiff
del dm_cars_dcr.tiff_original

IM v6.8.9-5 complains about dcraw's version of the sRGB profile, so strip it, and all other metadata.

%IM%convert dm_cars_dcr.tiff -strip dm_cars_dcr.tiff

Now we make an image for the web:

%IM%convert ^
  dm_cars_dcr.tiff ^
  %WEB_SIZE% ^

call %PICTBAT%mHist dm_cars_dcr.tiff
dm_cars_dcr.jpg dm_cars_dcr_hist.png

Compared to the in-camera JPEG, this result has slightly darker midtones (the two cars), but lighter shadows (eg the wheel arch of the red car). The histogram shows marked clipping. This occurs at the red car's windscreen frame. Statistics shows that 0.6% of pixels are white.

call %PICTBAT%stats dm_cars_dcr.tiff 
min=0    max=0    mean=0    SD=0
satMin=0 satMax=0 satMean=0 satSD=0

Extracting raw sensor data

We can tell dcraw to give us the raw almost unprocessed sensor data, and process it with ImageMagick. We do, however, ask dcraw to "automatically brighten" the image, by omitting "-W", upper-case W. "Automatic brighten" is similar to to IM's "-auto-level", but only stretches towards white, and uses bins, and allows clipping. Without "automatic brighten", the maximum value from this image would be 16383.

%IM%dcraw -v -o 0 -6 -r 1 1 1 1 -g 1 0 -D -d -T -O dm_cars_rggb.tiff %CAMERA_SRC%.nef 
Loading Nikon D800 image from \pictures\20130713\AGA_1369.nef ...
Platform 0: Intel(R) Corporation OpenCL 1.2 
	Device 0: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
	Device 1: Intel(R) HD Graphics 4600  <---
Building histograms...
Writing data to dm_cars_rggb.tiff ...
exiftool -tagsfromfile dm_cars_rggb.tiff dm_cars_rggb.tiff
del dm_cars_rggb.tiff_original

For the web, we convert this to sRGB, and make the crops.

%IM%convert dm_cars_rggb.tiff ^
  -set colorspace RGB -colorspace sRGB ^
  -write dm_r_cars.tiff ^
  -write info: ^
  ( +clone %WEB_SIZE% -write dm_r_cars.jpg +delete ) ^
  ( +clone -crop 8x8+1200+2000 +repage -auto-level -write dm_r_red_car.png +delete ) ^
  ( +clone -crop 8x8+2400+4300 +repage -auto-level -write dm_r_green_grass.png +delete ) ^
  ( +clone -crop 8x8+6400+1500 +repage -auto-level -write dm_r_blue_car.png +delete ) ^
dm_cars_rggb.tiff TIFF 7424x4924 7424x4924+0+0 16-bit Grayscale Gray 73.15MB 15.063u 0:02.858
set bpText=Red car
call %PICTBAT%blockPix dm_r_red_car.png
set bpText=Green grass
call %PICTBAT%blockPix dm_r_green_grass.png
set bpText=Blue car
call %PICTBAT%blockPix dm_r_blue_car.png
set bpText=

call %PICTBAT%mHist dm_r_cars.tiff
dm_r_cars.jpg dm_r_red_car_bp.png dm_r_green_grass_bp.png dm_r_blue_car_bp.png dm_r_cars_hist.png
call %PICTBAT%stats dm_r_cars.tiff 
min=0.00256352    max=1    mean=0.378814    SD=0.1927
satMin=0 satMax=0 satMean=0 satSD=0

Note the heavy clipping.

This differs from the JPEG image:

  1. It is larger than the JPEG. It is 64 pixels wider and 12 pixels higher. Therefore the crops show different areas.
  2. It is greyscale because each pixel has recorded only one of red, green or blue.
  3. It is dark because the values are linear, but also because I under-exposed to prevent the specular highlights from burning out. I have applied auto-level to each crop so we can see...
  4. ... the enlarged crops all show a repeated 2x2 pattern, a Bayer mosaic.
  5. Although not clear in this image, there is a border effect on the right-hand side, which needs cropping off.

For the red car, the lightest pixel in each group of 2x2 pixels represents the red channel. Likewise for the blue car and blue channel. The other two pixels are green channels.

So the Bayer pattern is:

R G0
G1 B

To illustrate the effect of the Bayer filter, we can process dm_r_cars.tiff by coloring each pixel either red, green or blue, with the script colmos.bat.

call %PICTBAT%colmos dm_r_cars.tiff

%IM%convert ^
  %clmOUTFILE% ^
  ( +clone %WEB_SIZE% -write dm_r_cars_c.jpg +delete ) ^
  ( +clone -crop 8x8+1200+2000 +repage -auto-level -write dm_r_red_car_c.png +delete ) ^
  ( +clone -crop 8x8+2400+4300 +repage -auto-level -write dm_r_green_grass_c.png +delete ) ^
  ( +clone -crop 8x8+6400+1500 +repage -auto-level -write dm_r_blue_car_c.png +delete ) ^

set bpText=Red car
call %PICTBAT%blockPix dm_r_red_car_c.png
set bpText=Green grass
call %PICTBAT%blockPix dm_r_green_grass_c.png
set bpText=Blue car
call %PICTBAT%blockPix dm_r_blue_car_c.png
set bpText=

call %PICTBAT%mHist dm_r_cars_clm.tiff
dm_r_cars_c.jpg dm_r_red_car_c_bp.png dm_r_green_grass_c_bp.png dm_r_blue_car_c_bp.png dm_r_cars_clm_hist.png

The overall image is tinted green because there are twice as many green pixels than either red or blue. The results are dark because each of the pixels has a value in only one channel. The other two channels are zero. The demoasicing process will spread values from nearby pixels, so those values will no longer be zero.

Knowing the Bayer pattern, we can write a script, demos.bat, that demosaics an image. The script makes four clones at 50% size, using "-sample 50%" to get the exact pixel values without interpolation. The offsets define which of the four pixels in a group is chosen. For example, "-define sample:offset=75x25" chooses the top-right within each group.

The demosaicing is done by "-resize", which stretches each pixel, doubling it in each dimension. Each channel is stretched separately. This primitive method of demosaicing will introduce false colours at boundaries, though these are not visible at reductions made for the web.

In debug mode, the script also makes block-pixel versions.

set dmDEBUG=1
call %PICTBAT%demos dm_r_red_car.png
call %PICTBAT%demos dm_r_green_grass.png
call %PICTBAT%demos dm_r_blue_car.png
set dmDEBUG=
dm_r_red_car_dm_bp.png dm_r_green_grass_dm_bp.png dm_r_blue_car_dm_bp.png

This has demosaiced the three small crops. (However, they were converted to sRGB and then demosaiced. This should be done in the opposite order: demosaic first, then convert to sRGB.)

Before demosaicing the full-size image, we will consider colour balance.

Colour balance

For this camera, the photo-receptors for red and blue are less sensitive than those for green, so the red and blue values need to be multiplied by a number greater than one. In addition, the camera records the redness or blueness of the light. It combines these two effects and writes multipliers for the red and blue channels in exif data. I extract this with exiftool from the original NEF file.

set RedBalance=1.8
set BlueBalance=1.4

for /F "usebackq tokens=1,2*" %%i ^
in (`exiftool -p "$RedBalance $BlueBalance" %CAMERA_SRC%.nef`) ^
do (
  set RedBalance=%%i
  set BlueBalance=%%j
echo %RedBalance% %BlueBalance% 
1.933594 1.394531 

These multipliers were automatically used above in Conventional processing with dcraw.

The script can use these multipliers. Multiplying a pixel value by nearly 2 might cause clipping. dcraw contains code that can deal with this, eg by reducing all four multipliers by the same proportion, such that no channel quite clips.

So we can now demosaic the full image, giving a reasonable result. We also convert to sRGB and increase saturation.

call %PICTBAT%demos dm_cars_rggb.tiff %RedBalance% 1 1 %BlueBalance%

%IM%convert ^
  dm_cars_rggb_dm.tiff ^
  -set colorspace RGB -colorspace sRGB ^
  -modulate 100,200,100 ^
  -write dm_cars_demos.tiff ^
  %WEB_SIZE% ^

call %PICTBAT%mHist dm_cars_demos.tiff
dm_cars_demos.jpg dm_cars_demos_hist.png

The bad pixels on the right edge are more visible now, as a vertical black stripe at the edge. The width varies with different focal-length lenses, being wider with wide-angle lenses. It is outside the advertised limits of the camera, so not a problem.

The frame around the windscreen of the red car has clipped. The script could be modified to avoid clipping, for example by finding the maximum values in the RGGB channels and reducing the four multipliers by the same factor such that no channel clips.

call %PICTBAT%stats dm_cars_demos.tiff 
min=0    max=1    mean=0.420864    SD=0.233387
satMin=0 satMax=1 satMean=0.218671 satSD=0.200203

We can use choose the filter to be used for the resize. The following code creates a sample for each filter, cropping near the bottom-left of the image, showing the blue car's reflection in the red car's bumper (= USA "fender").

set CROP_BUMPER=-crop 350x260+280+3540 +repage

for /F "usebackq" %%F in (`%IM%convert -list filter`) do (
  call %PICTBAT%demos dm_cars_rggb.tiff %RedBalance% 1 1 %BlueBalance% %%F

  %IM%convert ^
    dm_cars_rggb_dm.tiff ^
    -set colorspace RGB -colorspace sRGB ^
    ^( +clone ^
       -fill #ffffff -colorize 100 ^
       -gravity Center -fill #000000 -annotate 0 %%F ^
       -trim -bordercolor #ffffff -border 2 ^
    ^) ^
    -append ^

For comparison, we make the same crop from the conventional demosaicing by dcraw, above.

%IM%convert ^
  dm_cars_dcr.tiff ^
  ^( +clone ^
     -fill #ffffff -colorize 100 ^
     -gravity Center -fill #000000 -annotate 0 "dcraw" ^
     -trim -bordercolor #ffffff -border 2 ^
  ^) ^
  -append ^

Box and Point make a blocky image. Sinc and SincFast create horrible ringing. Cubic, Gaussian, Spline and Triangle make soft edges. Differences between the other filters are more subtle.

dm_filt_Box.png dm_filt_Sinc.png dm_filt_Cubic.png dm_filt_Kaiser.png dm_dcr_crop.png dm_filt_Lanczos.png dm_filt_Robidoux.png dm_filt_RobidouxSharp.png

We are upsampling each of the four channels (RGGB). Nicolas Robidoux, Bart van der Wolf and others are developing techniques for minimizing halos when up- or down-sampling. See my page Resampling with halo minimization. I implement one of the techniques in demos.bat. I reckon the "sharpness amount" needs setting to 70 for a similar sharpness to the default Lanczos filter, so my script hard-codes this value. To activate this technique, run the script with dmMIN_HALO set to 1. It slows the script (69 seconds versus 29 seconds).

set dmMIN_HALO=1

call %PICTBAT%demos dm_cars_rggb.tiff %RedBalance% 1 1 %BlueBalance% . dm_filt_hm.tiff

%IM%convert ^
  dm_filt_hm.tiff ^
  -set colorspace RGB -colorspace sRGB ^
  ^( +clone ^
     -fill #ffffff -colorize 100 ^
     -gravity Center -fill #000000 -annotate 0 "HaloMin" ^
     -trim -bordercolor #ffffff -border 2 ^
  ^) ^
  -append ^

set dmMIN_HALO=

Compare the halo-minimized version with the default Lanczos version made above:

dm_filt_hm.png dm_filt_Lanczos.png

I can't say that I prefer one over the other. If I had better eyesight, perhaps I would.

Simpler brightening

Instead of using dcraw's auto-brighten or IM's -auto-level, we might multiply by four. (The camera is 14 bits/channel and we want 16 bits/channel.)

%IM%dcraw -v -o 0 -W -6 -r 1 1 1 1 -g 1 0 -D -d -T -O dm_cars_rggb4.tiff %CAMERA_SRC%.nef 
Loading Nikon D800 image from \pictures\20130713\AGA_1369.nef ...
Platform 0: Intel(R) Corporation OpenCL 1.2 
	Device 0: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
	Device 1: Intel(R) HD Graphics 4600  <---
Building histograms...
Writing data to dm_cars_rggb4.tiff ...
exiftool -tagsfromfile dm_cars_rggb4.tiff dm_cars_rggb4.tiff
del dm_cars_rggb4.tiff_original

We demosaic and convert to sRGB. We don't bother to make crops.

set dmDEBUG=
call %PICTBAT%demos dm_cars_rggb4.tiff %RedBalance% 1 1 %BlueBalance%

%IM%convert ^
  dm_cars_rggb4_dm.tiff ^
  -evaluate Multiply 4 ^
  -set colorspace RGB -colorspace sRGB ^
  -modulate 100,200,100 ^
  -write dm_cars_demos4.tiff ^
  %WEB_SIZE% ^

call %PICTBAT%mHist dm_cars_demos4.tiff
dm_cars_demos4.jpg dm_cars_demos4_hist.png

There is still clipping, but less than from dcraw's auto-brighten.

call %PICTBAT%stats dm_cars_demos4.tiff 
min=0    max=1    mean=0.238553    SD=0.151426
satMin=0 satMax=1 satMean=0.135198 satSD=0.122078

The result is too dark. gamMaxSd (see Adding zing to photographs) improves it:

call %PICTBAT%gamMaxSd dm_cars_demos4.tiff

%IM%convert ^
  dm_cars_demos4.tiff ^
  -evaluate Pow %gmsPOW_MAX_SD% ^
  -write dm_cars_demos5.tiff ^
  %WEB_SIZE% ^

call %PICTBAT%mHist dm_cars_demos5.tiff
dm_cars_demos5.jpg dm_cars_demos5_hist.png
call %PICTBAT%stats dm_cars_demos5.tiff 
min=0    max=1    mean=0.375608    SD=0.162022
satMin=0 satMax=1 satMean=0.148603 satSD=0.138934

With so much chrome, I think the contrast (as measured by standard deviation) could be increased. Just for fun, set the SD to the same as the camera's JPEG image. Of course, the JPEG's SD may not be the best aesthetically. (See also Adding zing to photographs.)

set sssGOAL_SD=%jpegSD%
call %PICTBAT%sigSetSd dm_cars_demos5.tiff mean 
set sssGOAL_SD=

%IM%convert ^
  dm_cars_demos5.tiff ^
  %sssOPTION% ^
  -write dm_cars_demos6.tiff ^
  %WEB_SIZE% ^

call %PICTBAT%mHist dm_cars_demos6.tiff
dm_cars_demos6.jpg dm_cars_demos6_hist.png
call %PICTBAT%stats dm_cars_demos6.tiff 
min=0    max=1    mean=0.461588    SD=0.241773
satMin=0 satMax=1 satMean=0.225838 satSD=0.207887


ImageMagick can demosaic raw camera images, and it does so quite well.


Interesting references, though not particularly relevant to this page, are:


We don't need to keep all those large TIFF files, so delete them.

del dm_*_*.tiff


For convenience, .bat scripts are also available in a single zip file. See Zipped BAT files.


@for /F "usebackq" %%L in (`%IM%convert ^
  %* ^
  -format "statMIN=%%[fx:minima]\nstatMAX=%%[fx:maxima]\nstatMEAN=%%[fx:mean]\nstatSD=%%[fx:standard_deviation]\n" ^
  -write info: ^
  ^( +clone ^
    -colorspace HCL ^
    -format "statSatMin=%%[fx:minima.g]\nstatSatMax=%%[fx:maxima.g]\nstatSatMean=%%[fx:mean.g]\nstatSatSD=%%[fx:standard_deviation.g]\n" ^
    -write info: ^
    +delete ^
  ^) ^
  -fill #000 +opaque #fff -format "statPropWhite=%%[fx:mean]" ^
  info:`) do @set %%L

@echo min=%statMIN%    max=%statMAX%    mean=%statMEAN%    SD=%statSD%
@echo satMin=%statSatMin% satMax=%statSatMax% satMean=%statSatMean% satSD=%statSatSd%
@echo propWhite=%statPropWhite%


rem From image %1, makes histogram image.

@if "%1"=="" findstr /B "rem @rem" %~f0 & exit /B 1

@setlocal enabledelayedexpansion

rem call echoOffSave

@set INFILE=%~f1
@set OUTFILE=%~dpn1_hist.png

%IM%convert ^
  %INFILE% ^
  -define histogram:unique-colors=false ^

%IM%convert ^
  -bordercolor #000 -border 2 ^

call echoRestore


rem From %1, a Bayer mosaic image,
rem makes demosaiced image, same size.
rem %2 %3 %4 and %5 are multipliers for R G0 G1 and B channels.
rem %6 is optional filter for resize.
rem %7 is optional output file.
@rem Also uses:
@rem   dmMIN_HALO  if 1, uses experimental technique for minimising halos.
@rem   dmDEBUG     if 1, creates extra debugging outputs.
@rem Assumes Bayer filter pattern is:
@rem   R  G0
@rem   G1 B

@if "%1"=="" findstr /B "rem @rem" %~f0 & exit /B 1

@setlocal enabledelayedexpansion

call echoOffSave

call %PICTBAT%setInOut %1 dm

set FILT=%6

if not "%7"=="" if not "%7"=="." set OUTFILE=%7

if "%dmDEBUG%"=="1" (
  set dm_WR_R=-write %BASENAME%_R.png
  set dm_WR_G0=-write %BASENAME%_G0.png
  set dm_WR_G1=-write %BASENAME%_G1.png
  set dm_WR_B=-write %BASENAME%_B.png
) else (
  set dm_WR_R=
  set dm_WR_G0=
  set dm_WR_G1=
  set dm_WR_B=

for /F "usebackq" %%L ^
in (`%IM%identify -format "WW=%%w\nHH=%%h" %INFILE%`) ^
do set /A %%L

set MULT_R=
set MULT_G0=
set MULT_G1=
set MULT_B=

if not "%2"=="" if not "%2"=="." set MULT_R=-evaluate Multiply %2
if not "%3"=="" if not "%3"=="." set MULT_G0=-evaluate Multiply %3
if not "%4"=="" if not "%4"=="." set MULT_G1=-evaluate Multiply %4
if not "%5"=="" if not "%5"=="." set MULT_B=-evaluate Multiply %5

set sFILT=

if not "%FILT%"=="" if not "%FILT%"=="." set sFILT=-filter %FILT%

set RESIZE=-resize "%WW%x%HH%^^^!"

if "%dmMIN_HALO%"=="1" (

  set shpAmount=70

  for /f "usebackq" %%L in (`%IM%identify ^
    -precision 16 ^
    -format "deblurValue=%%[fx:1-0.0011450938298236*!shpAmount!]" ^
    xc:`) do set %%L

  set FILT=-define filter:blur=!deblurValue! -filter Lanczos -distort Resize "%WW%x%HH%^^^!"

  set gamIn=-gamma 3
  set gamOut=-gamma 0.3333333333333333

  set RESIZE= ^
    ^( -clone 0 !gamIn! !FILT! !gamOut! ^) ^
    ^( -clone 0 !FILT! ^) ^
    -delete 0 ^
    ^( -clone 1 -colorspace gray -auto-level ^) ^
    -compose over -composite

%IM%convert ^
  %INFILE% ^
  %sFILT% ^
  ( -clone 0 -define sample:offset=25 -sample 50%% %MULT_R% ^
    %RESIZE% %dm_WR_R% ) ^
  ( -clone 0 ^
    ( -clone 0 -define sample:offset=75x25 -sample 50%% %MULT_G0% ^
      %RESIZE% %dm_WR_G0% ) ^
    ( -clone 0 -define sample:offset=25x75 -sample 50%% %MULT_G1% ^
      %RESIZE% %dm_WR_G1% ) ^
    -delete 0 ^
    -evaluate-sequence mean ^
  ) ^
  ( -clone 0 -define sample:offset=75 -sample 50%% %MULT_B% ^
    %RESIZE% %dm_WR_B% ) ^
  -delete 0 ^
  -combine ^
  %COMPR% ^

if ERRORLEVEL 1 exit /B 1

if "%dmDEBUG%"=="1" (
  set bpText=%~n1_R
  call %PICTBAT%blockPix %BASENAME%_R.png
  set bpText=%~n1_G0
  call %PICTBAT%blockPix %BASENAME%_G0.png
  set bpText=%~n1_G1
  call %PICTBAT%blockPix %BASENAME%_G1.png
  set bpText=%~n1_B
  call %PICTBAT%blockPix %BASENAME%_B.png
  set bpText=%~n1_RGB
  call %PICTBAT%blockPix %OUTFILE%

call echoRestore

endlocal & set dmOUTFILE=%OUTFILE%


rem From %1, a Bayer mosaic image,
rem colours each pixel with red, green or blue.
rem %2 %3 %4 and %5 are multipliers for R G0 G1 and B channels.
rem %6 is optional output file.
@rem Assumes Bayer patern is:
@rem   R  G0
@rem   G1 B

@if "%1"=="" findstr /B "rem @rem" %~f0 & exit /B 1

@setlocal enabledelayedexpansion

@call echoOffSave

call %PICTBAT%setInOut %1 clm

if not "%6"=="" if not "%7"=="." set OUTFILE=%6

for /F "usebackq" %%L ^
in (`%IM%identify -format "WW=%%w\nHH=%%h" %INFILE%`) ^
do set /A %%L

%IM%convert ^
  ( xc:red  xc:lime +append ) ^
  ( xc:lime xc:blue +append ) ^
  -append ^
  -write mpr:BAYER +delete ^
  -size %WW%x%HH% ^
  tile:mpr:BAYER ^
  %INFILE% ^
  -compose Multiply -composite ^

call echoRestore

endlocal & set clmOUTFILE=%OUTFILE%

All images on this page were created by the commands shown, using:

%IM%identify -version
Version: ImageMagick 6.9.5-3 Q16 x86 2016-07-22
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

Source file for this web page is demosaic.h1. To re-create this web page, execute "procH1 demosaic".

This page, including the images, is my copyright. Anyone is permitted to use or adapt any of the code, scripts or images for any purpose, including commercial use.

Anyone is permitted to re-publish this page, but only for non-commercial use.

Anyone is permitted to link to this page, including for commercial use.

Page version v1.1 1-October-2014.

Page created 03-Aug-2016 11:06:14.

Copyright © 2016 Alan Gibson.