Combined convert commands - UNIX - buggy

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
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Combined convert commands - UNIX - buggy

Post by geoland »

Version: ImageMagick 7.0.6-0 Q16 x86_64 2017-06-26 xubuntu 16.04

The following commands generate individual R G B L L* channels as well as combining into LRGB and L*RGB images.

I have attempted a couple of -clone examples below combining lines 1, 2 and 3 and lines 4, 5 and 6 - working but buggy?

Given that the remainder have different input files, is there a way of combining into fewer convert commands.

Code: Select all

convert stack.miff -depth 16 -separate %d.miff

	convert stack.miff -depth 16 -colorspace Gray -separate -average L.miff

	convert stack.miff -depth 16 -colorspace LAB -separate %d_lab.miff
	
	convert 0.miff -depth 16 R.tiff
	convert 1.miff -depth 16 G.tiff
	convert 2.miff -depth 16 B.tiff
	
	convert L.miff -depth 16 +compress -auto-level L.tiff

	convert 0_lab.miff -depth 16 +compress MASK.tiff
	
	convert 0.miff 1.miff 2.miff L.miff -depth 16 +compress -colorspace sRGB -combine -alpha off LRGB.tiff
	
	convert 0.miff 1.miff 2.miff 0_lab.miff -depth 16 +compress -colorspace sRGB -combine -alpha off LightRGB.tiff
Lines 1, 2, 3 - works but continues to generate %d_lab.miff images until CtrlC kills the process. Though this is likely a bash issue.

Code: Select all

convert stack.miff \( -clone 0 -depth 16 -separate +write %d.miff \)  \
\( -clone 0 -depth 16 -colorspace Gray -separate -average +write L.miff \) \
-depth 16 -colorspace LAB -separate %d_lab.miff
Lines 4, 5, 6 - fails to write B.miff properly. And I am not certain the R G B files are being generated in strict order.

Code: Select all

convert 0.miff 1.miff 2.miff \( -clone 0 -depth 16 +write R.miff \) \
\( -clone 1 -depth 16 +write G.miff \) \
-depth 16 B.miff
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combined convert commands - UNIX - buggy

Post by fmw42 »

convert stack.miff -depth 16 -colorspace Gray -separate -average L.miff
The -separate -average does nothing here. Once you convert to grayscale, you have one channel thought it is duplicated as R,G,B in IM 6. In IM 7, you just get one grayscale channel. So this is equivalent to

Code: Select all

convert stack.miff -depth 16 -colorspace Gray L.miff
If your stack.miff file has only one layer, then this should work fine. Note you have to delete the clones after writing them otherwise, you last line will try to use all the image created by all clones and the original.

Code: Select all

convert stack.miff \( -clone 0 -depth 16 -separate +write %d.miff +delete \)  \
\( -clone 0 -depth 16 -colorspace Gray +write L.miff +delete \) \
-depth 16 -colorspace LAB -separate %d_lab.miff
If your miff is multi-layer, I am not sure if this command will work or not when you separate channels. It might, but I have not tested that.
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Re: Combined convert commands - UNIX - buggy

Post by geoland »

Thank you. RGB Channel separation was problematic using -clone. 0 1 2 should equate to R G B but the channels appeared to have been swapped (when recombined).

Code: Select all

convert stack.tiff -separate %d.miff
produces 4 channels. 4 being the alpha channel???

LAB channel separation didn't work with -clone - the documentation indicates the following in IM7 and this seems to work in IM6 as well (the ubuntu version)

Code: Select all

convert stack.miff -colorspace LAB -separate -channel L L.miff
producing a grayscale image. Is -separate redundant having declared -channel L?
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combined convert commands - UNIX - buggy

Post by fmw42 »

try

Code: Select all

convert stack.tiff -separate +channel %d.miff
Is your tiff file RGBA or CMYK?

Code: Select all

identify stack.tiff
If the above does not work, then upload your stack.tiff image to some free hosting service and post the URL here
Post Reply