Mimic a sequenve of photoshop commands to process raw fuji

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
djehem
Posts: 2
Joined: 2013-05-29T13:49:53-07:00
Authentication code: 6789

Mimic a sequenve of photoshop commands to process raw fuji

Post by djehem »

I have found a great article on developping raw files coming from a x-trans sensor (http://www.fujifilm.eu/uk/products/digi ... echnology/) camera (fuji x-pro1) written by Terrance Lam :

http://www.frontallobbings.com/2012/11/ ... 1-raf.html

The idea is to use the dcraw program to develop the raw file into a 16 bits tiff and the use photoshop to do further processing of the images according to the following protocole :

The Process
1. Using command line DCRAW: dcraw -a -H 0 -o 4 -q 1 -f -m 15 -g 2.4 12.9 -6 -T
2. Convert TIFF file to LAB file in Photoshop
3. Resize image 200% with Bicubic Smoother
4, Select Lightness Channel under channel panel.
5. Select Median filter under Noise in Filter. Select 1 pixel
6. Resize image 50% with Bicubic Sharper (Nearest Neighbour is actually a more subtle effect which I kind of prefer)
7. Save.

Is there here a wizzard who could snap ;-) the photoshop command from 2 to 7 in the preceding process into imagemagick commands to put them in a bash script

Thanks in advance

djehem
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mimic a sequenve of photoshop commands to process raw

Post by snibgo »

See http://www.imagemagick.org/script/comma ... ptions.php for all the commands.

The only issue would be "bicubic smoother" and "bicubic sharper". See many threads in viewforum.php?f=22 about resizing filters that may or may not yield similar results.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mimic a sequenve of photoshop commands to process raw

Post by fmw42 »

We do not know exactly what PS uses for bicubic resampling, but it is likely similar to the cubic convolution used in the Catrom Filter (ie. Key's cubic convolution). For resizing, see -resize and -distort resize and see cubic filter family at http://www.imagemagick.org/Usage/filter/ with its defines for blurring and sharpening and also recommendations at http://www.imagemagick.org/Usage/filter/nicolas/. PS often adds some unsharp masking after resizing. See -unsharp

you can convert the image to LAB using

convert image -colorspace LAB ...

you can separate channels using -separate and then recombine using -combine

you can apply a median filter using -statistic median 3x3 for a 1 pixel radius equivalent

I have a bash shell script, enhancelab, at the link below that enhances color in LAB space (for unix and mac)

Everything you mention is easily put into a command line in IM, but the hard part is picking the appropriate resizing filters. That you will have to do with trial and error and comparing to results from PS.

The command line might be something like

convert image -colorspace LAB -filter XXX -resize 200% -channel R -statistic median 3x3 +channel -filter YYY -resize 50% resultimage

Here channel R is the L channel after converting to LAB


Or

convert image -colorspace LAB -filter XXX -resize 200% -separate +channel \
\( -clone 0 -statistic median 3x3 \) -swap 0,3 +delete -set colorspace LAB -combine \
-colorspace sRGB -filter YYY -resize 50% resultimage


The above commands are unix syntax. For windows see http://www.imagemagick.org/Usage/windows/


Also I do not understand why one would want to add extra blurring/smoothing while enlarging (bicubic smoother?). Most resize filters will blur to some extent anyway. This is especially true if you are then going to apply a median filter after enlarging. One might smooth when shrinking to avoid moire and other artifacts, but this is not likely a problem with enlarging.

Perhaps one of the photographers can elaborate or comment on this further.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mimic a sequenve of photoshop commands to process raw

Post by snibgo »

Interestingly, "-statistic median 2x2" does something, slightly less than "3x3", and slightly more than "1x1" (which does nothing).

With "-statistic median 0.5x0.5", IM ignores each "0." and gives us "5x5"!

Windows script:

Code: Select all

"%IMG685%convert" m.png ^
  -set colorspace sRGB -colorspace Lab ^
  -separate ^
  ( -clone 0 -resize 200%% -statistic median 2x2 -resize 50%% ) ^
  -swap 0,3 -delete 3 ^
  -combine ^
  -set colorspace Lab -channel RGB -colorspace sRGB ^
  mm.png
Maybe with "2x2" the OP wouldn't need the resizing.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mimic a sequenve of photoshop commands to process raw

Post by fmw42 »

snibgo:

-statistic to my understanding uses rectangular areas and not a radius or sigma. So it only works with integer sizes. I was not even sure it would use even integers. That might cause half pixel shifts. Median filtering should not be changing the image size, so it should have nothing to do with resizing or not.

You could go back to the deprecated -median 1 for a 3x3 median filter.

If you are working with IM 6.8.5.5 or higher you should not need the -set colorspace sRGB at the beginning and the -channel rgb I think is superfluous. Adding -set colorspace sRGB may mislabel an RGB (linear) input. It would be better to use -colorspace sRGB which would not affect the input if already sRGB.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mimic a sequenve of photoshop commands to process raw

Post by snibgo »

I cross-posted with your first post, Fred.

I agree you about "set colorspace sRGB", especially as the OP's link shows the input file coming from dcraw, where the colorspace is ProPhoto RGB. As IM doesn't understand that colorspace, the dcraw command option should be changed to "-o 1", which is sRGB.

I resize only the L channel (of Lab); in the link cited by the OP, the resize is only to get a Lightness median at 0.5 pixel radius.

Compared to Nicolas Robidoux, Anthony, etc I know nothing about the mechanics of filtered resizes and associated blurring, and I'm not familiar with the PS methods, and I've never played with that camera and its 6x6 sensor matrix.

For photography, the impact of sharpening, blurring, and noise (or grain) have been argued since the dawn of, well, photography. I doubt that I would ever want to remove detail during enlargement, unless it was to remove a perceived blockiness.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mimic a sequenve of photoshop commands to process raw

Post by fmw42 »

Is there a particular reason to only resize the L channel? The OP wanted all channels resized. Though I suppose there is reason to believe that you are correct. Resizing the other channels that are not processed further can only add artifacts or blurring and at best leave things the same but waste time and computations.

With regard to resizing, I would recommend using IM's defaults (which I believe are Mitchell for enlarging and Laczos for shrinking). However, in my opinion if one wants sharper results then perhaps try using Catrom or Lagrange when enlarging or possibly both ways. But I have not tested that except for enlarging certain kinds of images. I think Mitchell is a bit too soft (blurry) when enlarging.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mimic a sequenve of photoshop commands to process raw

Post by snibgo »

From the link cited in the OP:
By using Photoshop, converting the file to a LAB based TIFF, I then used Median filtering in photoshop to rid of the zippered effects only in the Lightness channel. However you can't do 1/2 pixels in Photoshop. Initially I tried to do this with 1 pixel, but it lost a significant amount of details in textures. I decided to resize the image by a factor of 2, apply the 1 pixel Median filter, then resize it back down to the original size. This got rid of the aliasing artifacts that result in DCRAW or RPP produced images.
Resizing all channels also causes some blur in the a and b channels. This might or might not be desirable, which I why I mentioned it in the text. I encourage the OP to experiment and find what works best.

(My own philosophy is: "Remove detail if that improves the image. Otherwise, don't.")
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mimic a sequenve of photoshop commands to process raw

Post by snibgo »

I downloaded a sample image for this camera from dpreview ...
http://s3.amazonaws.com/movies.dpreview ... 00-RAF.zip
... and ran it through:

Code: Select all

%IMG6858%dcraw -v -a -H 0 -o 1 -q 1 -f -m 15 -g 2.4 12.9 -6 -T -O fuji.tif DSCF9557.RAF

"%IMG6858%convert" fuji.tif ^
  -set colorspace sRGB -colorspace Lab ^
  -separate ^
  ( -clone 0 -resize 200%% -resize 50%% ) ^
  -swap 0,3 -delete 3 ^
  -combine ^
  -set colorspace Lab -channel RGB -colorspace sRGB ^
  fuji2.tif

"%IMG6858%convert" fuji.tif ^
  -set colorspace sRGB -colorspace Lab ^
  -separate ^
  ( -clone 0 -resize 200%% -statistic median 2x2 -resize 50%% ) ^
  -swap 0,3 -delete 3 ^
  -combine ^
  -set colorspace Lab -channel RGB -colorspace sRGB ^
  fuji2_2x2.tif
fuji2.tif has the resize but no median filter. fuji2_2x2.tif has the resize with a median 2x2 filter.

Displaying the results so they are 17 inches wide on the monitor, the results look fine. Viewing them at 1:1, ie each camera pixel is one pixel on the screen (aka pixel-peeking), fuji2.tif is slightly but distinctly softer than fuji.tif, as we would expect. fuji2_2x2.tif is (I would say) slightly softer still, with no apparent advantage.

But I shouldn't draw conclusions from a single example, and my conclusions shouldn't matter. The softening could easily be subjectively retrieved.
snibgo's IM pages: im.snibgo.com
djehem
Posts: 2
Joined: 2013-05-29T13:49:53-07:00
Authentication code: 6789

Re: Mimic a sequenve of photoshop commands to process raw

Post by djehem »

Thanks a million time for all your responses. I'll work hard on them and get back to you all to show the results

djehem
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mimic a sequenve of photoshop commands to process raw

Post by snibgo »

In my last script, I forgot to remove "-set colorspace sRGB" at the start of each convert. They shouldn't be there (but are harmless, in this case).
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mimic a sequenve of photoshop commands to process raw

Post by snibgo »

Here's another experiment (Windows script):

Code: Select all

"%IMG6858%convert" fuji.tif ^
  -colorspace Lab ^
  -separate ^
  ( -clone 0 ^
    -filter Point -resize 200%% ^
    -statistic median 3x3 ^
    -filter Lanczos -resize 50%% ^
  ) ^
  -swap 0,3 -delete 3 ^
  -combine ^
  -set colorspace Lab -channel RGB -colorspace sRGB ^
  fuji2_3x3.tif
The resizing now hardly changes the image at all. (If the resize 50% was also "-filter Point", the resizes would have zero effect).

I've changed the median to 3x3, as 2x2 has no effect. (It would do a median of a 2x2 rectangle, and all those pixels would be exactly the same.)

The result is a very slight softening that (to my eyes) is detrimental to the brickwork but improves the appearance of the smooth tones of the window and blinds.

In particular, it reduces the staircase effect of the diagonal window frames.
snibgo's IM pages: im.snibgo.com
Post Reply