Page 1 of 1

combine filters: bicubic (shadows) & lagrange (highlights)

Posted: 2013-12-30T07:43:55-07:00
by tackd
Hi.

Can I combine (2) different filters for downsizing photos ?

I like bicubic for the shadow areas of a photo
I like Lagrange for the highlight areas of a photo

I want to do this in 1 operation if possible

Thank you.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T08:00:58-07:00
by snibgo
One way of doing this would be to do both resizes, then merge them together with a mask, so the dark pixels come from the bicubic resize and the light pixel come from the Lagrange resize. Intermediate shades would be a blend of the two.

The command would be something like this (Windows syntax):

Code: Select all

convert ^
  input.tiff ^
  ( -clone 0 filter Cubic resize 25%% ) ^
  ( -clone 0 filter Lagrange resize 25%% ) ^
  ( -clone 2 ) ^
  +delete 0 ^
  -composite ^
  output.tiff
The third clone forms the mask. Where it is black, we get the cubic pixels, etc. You might want to blur the third clone to graduate the transition, so the pixels from dark areas come from cubic. You might also use "-sigmoidal-contrast" or even "-threshold" on the mask.

It might also be better to explicitly convert the third clone to grayscale.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T10:19:42-07:00
by tackd
Thanks snibgo.

I can combine 2 images more accurately in Photoshop, I am searching for a single operation in imagemagick.
For example, Photoshop uses 0-255 levels so, if I want
Levels: 0-128 IM filter bicubic
Levels: 128-255 Lagrange

...then combine the 2, is that possible in ImageMagick ?

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T10:52:18-07:00
by snibgo
Sure. Just threshold the mask at 50%:

Code: Select all

convert ^
  input.tiff ^
  ( -clone 0 filter Cubic resize 25%% ) ^
  ( -clone 0 filter Lagrange resize 25%% ) ^
  ( -clone 2 -threshold 50%% ) ^
  +delete 0 ^
  -composite ^
  output.tiff
(This is Windows syntax. Adjust as required for Unix or whatever.)

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T13:38:43-07:00
by tackd
Like this ?

$ convert input.tiff \( -clone 0 filter Cubic -resize 1024 \) \( -clone 0 filter Lagrange -resize 1024 \) \( -clone 2 -threshold 50%% \) +delete 0 -composite output.tiff

I think this will use the Cubic for values 0-128, and Lagrange for 129-255, then composite them together ?

I forgot, is it possible to slightly blur the mask used for the blend ?

Thank you again.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T13:56:36-07:00
by fmw42
convert input.tiff \( -clone 0 filter Cubic -resize 1024 \) \( -clone 0 filter Lagrange -resize 1024 \) \( -clone 2 -threshold 50%% \) +delete 0 -composite output.tiff

You have mixed Windows and Unix syntax and are missing the minus sign before filter (-filter). If on windows, remove all the \ . If on Unix make %% into %. If you want to blur the mask (and unix), then use

Code: Select all

convert input.tiff \( -clone 0 -filter Cubic -resize 1024 \) \( -clone 0 -filter Lagrange -resize 1024 \) \( -clone 2 -threshold 50% -blur 0x1 \) +delete 0 -composite output.tiff
For windows, use

Code: Select all

convert input.tiff ( -clone 0 -filter Cubic -resize 1024 ) ( -clone 0 -filter Lagrange -resize 1024 ) ( -clone 2 -threshold 50% -blur 0x1 ) +delete 0 -composite output.tiff

see
http://www.imagemagick.org/Usage/windows/
http://www.imagemagick.org/Usage/basics/#parenthesis

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T16:14:12-07:00
by tackd
fmw42,

System: Imagemagick 6.7.7.10-7 , Debian Testing

I tried your code...

Code: Select all

convert original.tif \( -clone 0 -filter Cubic -resize 1024 \) \( -clone 0 -filter LanczosSharp -resize 1024 \) \( -clone 2 -threshold 50% -blur 0x1 \) +delete 0 -composite output.tiff
Did I do that right ? I got some bizarre composite and it did not resize;

http://i836.photobucket.com/albums/zz29 ... 7f35f7.png

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T17:21:40-07:00
by fmw42
My oversight. It should be -delete 0 not +delete 0. Try the following with a few minor changes to play it safe

convert original.tif \( -clone 0 -filter Cubic -resize 1024x1024 \) \( -clone 0 -filter LanczosSharp -resize 1024x1024 \) \( -clone 2 -threshold 50% -blur 0x1 \) -delete 0 -compose over -composite output.tiff

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T21:53:36-07:00
by tackd
Fantastic !

Just what the doctor ordered... sucess, thanks so much.

One small problem, can you think of a reason Photoshop opens the image zoomed in all the way ?
It opens in Windows/Linux perfectly with Gimp Linux/Windows, but Photoshop CC 64 & Bridge
views the IM images so I can't see the whole image.

Thanks again.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T21:55:53-07:00
by fmw42
I cannot see there would be anything about the image that cause PS to do that. Perhaps there is some setting in PS that tells it a default zoom to use.

Does the input image zoom when opened in PS? Are the image formats the same (both tiff?). Perhaps it has to do with some tiff setting? Does it happen when both input and output images are PNG rather than TIFF?

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T22:15:01-07:00
by tackd
I opened the output.tif with Xnview, saved as uncompressed tif, then PS will open without problem... wierd.

png works as expected without error, must be some .tif saved related IM issue.

Should ignore these error messages ?

convert.im6: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Incompatible type for "FileSource"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Incompatible type for "SceneType"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/768.
convert.im6: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/768.

Thanks.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-30T23:11:12-07:00
by fmw42
It is not IM, but likely some tiff tag that IM does not understand.

All these are warnings that IM does not recognize one or more Tiff tags. Tiff is a very flexible format with regard to storing lots of specialized meta data. They all can be ignored.

I suspect one of the specialized tags stored in the tif file is telling it to be displayed in a zoomed mode. That tag will be ignored by many viewers. But since TIFF was originally a PS format, they probably recognize this tag and PS sees it an displays it accordingly.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-31T07:08:14-07:00
by tackd
I guess I could save to PNG, then pipe to IM tiff... hmmmm, maybe that would slap it into conformity.

I forgot, if I want to apply one filter to the shadow area only ( 0-64 ), would the code change like this;

Code: Select all

\( -clone 2 -threshold 25% \)
Thank you all so much, have a Happy, Healthy New Year.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-31T10:32:26-07:00
by snibgo
Yes, 25% would do the job.

Sorry for the syntax errors in my first post. Thanks to fmw for correcting them.

Re: combine filters: bicubic (shadows) & lagrange (highlight

Posted: 2013-12-31T13:15:40-07:00
by tackd
Thanks to all.
[SOLVED]