I am trying to convert some image (raw) that has no header, just the pixel values to a png, so I can view it. I found some information here (using imageMagik) and it works if the image is one channel. I used the command
convert -depth 8 -size 5312x2988+0 gray:image.raw pic.png
I searched more and I found that using the rpg is a way to treat more channels image, so I changed the syntax to
convert -depth 8 -size 5312x2988+0 rgb:image.raw pic.png
... but the output seems to be more like a 9x9 matrix containing the small images, like
R R R
G G G
B B B
The size is not wrong, but it may be the way the pixels are stored (interlaced/not-interlaced).
Can anyone help me to convert the 3-channel image, the correct way?
You could try specifying -interlace plane before the input file. Or maybe -interlace line, like this:
convert -interlace plane -depth 8 -size 5312x2988+0 rgb:image.raw pic.png
Like many ImageMagick parameters, you can enumerate the options at the command line with identify -list OPTION, so, in this case:
identify -list interlace
Output
Line
None
Plane
Partition
GIF
JPEG
PNG
Related
Using Gimp, given an input image, I can improve its contrast using Colors > Hue Chroma... by setting Chroma=50 (in a scale between -100 and 100) and leaving Hue=0 and Lightness=0. So it appears I'm doing an HCL transformation.
Is there an equivalent command for Magick?
The following image shows the GIMP effect:
Image
Updated Answer
Not sure about this at all. I think you can get pretty close with -modulate if you go into an LCH colourspace, but I have no idea if it will work consistently. I got:
magick cXDv3.jpg -define modulate:colorspace=LCH -modulate 100,150 result.jpg
If that doesn't work, or is not to your liking, read on...
Generic Method for any GIMP filters
The method below should allow you to replicate any GIMP filter with ImageMagick - as long as it is a pure "point process", I mean one where each pixel's output value is purely derived from its input value and not an "area process" where surrounding pixels contribute - such as blurring or median filtering, for example.
It's called a HALD-CLUT. You would create a HALD-CLUT something like this:
magick hald:16 clut.png
Then take that file (clut.png) into GIMP and apply your GIMP processing on it and save the result as GIMP-H0-C50-L0.png so we know how GIMP affects each colour. You do that just once.
Then you go back to ImageMagick and apply that CLUT to your image:
magick input.png GIMP-H0-C50-L0.png -hald-clut result.png
That gives me this:
and I think you'll agree the left side looks pretty similar to the right side of your input image.
Original Answer
I don't know what that command does in GIMP, but you can convert to HCL colourspace in ImageMagick and select the Chroma channel for modification like this:
magick INPUT.PNG -colorspace HCL -channel G ...
You then want to do something ? to affect the Chroma channel, so try -auto-level for now, and then return to sRGB colourspace and save:
magick INPUT.PNG -colorspace HCL -channel G -auto-level +channel -colorspace sRGB RESULT.PNG
Then you need to provide more clues or experiment more with what that command does in GIMP - or provide examples.
I'd like to convert an image from .jpg to .png. This works just fine:
convert input.jpg output.png
But, I'm trying to have my output go to STDOUT instead of a file, which the manual says to use "-".
I tried using:
convert input.jpg -.png
But it just creates a file called -.png.
Is it possible to convert an image from one format to another and have it go to STDOUT?
Yes, just use a command like this to convert a JPEG to a PNG on stdout:
magick input.jpg PNG:-
These specifiers work on input as well as output. So, if you have a TIFF on stdin and want a 32-bit RGBA PNG on stdout:
magick TIFF:- PNG32:-
You often need these specifiers to ensure a specific filetype when it is not explicitly given, or you want to use a different extension. So, say you have some CCD device that produces RGB data in a raw binary file called image.bin and you want ImageMagick to read it. You can tell ImageMagick the format without having to change the filename (to image.rgb) like this:
magick -size WxH RGB:image.bin result.png
The possible formats are documented here.
The king of all of these formats is MIFF which is guaranteed to be able to hold any and all things you might throw at it, including floating-point values, transparency, masks, concatenated streams... so if you need a format to pass between ImageMagick commands, MIFF is a good option. An example, just to demonstrate because it is not optimal, might to be to concatenate two images from 2 separate ImageMagick commands into a third command that makes an animated GIF:
{ magick -size 100x60 xc:red miff:- ; magick -size 100x60 xc:blue miff:- ; } | magick -delay 80 miff:- result.gif
I have tried adding the option -depth 12 to the string
convert transparentPNG.png -resize 500x400 -background white -flatten -depth 12 png_small.jpg
The input file is a transparent png to which I'm adding a background and then changing the depth. But the depth remains the same as 8bits. I verified the same using the -verbose.
I'm not sure what could I be doing wrong here. I'm referring to the site link
The transparent input png file used for my test can be found here
Let me know if you have any questions on the tests i did. Hoping to get some tips.
A JPG can only be 8-bit, so your internal 12-bit image is converted back to 8-bit when you save the result.
Is it possible to get the bit depth of a specific channel with an ImageMagick command?
I can see the individual channel depths with convert :rose -verbose info:, but I was wondering if there was a trick to only getting to print the alpha depth.
The reason I'm doing this is because I'm trying to write a script to figure out if an image either:
Does not support transparency (like JPEG)
Only supports ON/OFF transparency (like GIF)
Supports >1 bit transparency (like PNG)
I can check if the image is fully opaque with identify %[opaque] :rose, and was thinking I could check the type of transparency by checking if the alpha bit depth is greater than 1
In Imagemagick to get the bit depth of the alpha channel, try
convert transparent_image -alpha extract -format "%z\n" info:
or
convert transparent_image -alpha extract -format "%[depth]\n" info:
See http://www.imagemagick.org/script/escape.php
For example:
convert logo: -transparent white -alpha extract -format "%z" info:
8
However, this may actually be binary, but listed as 8-bits.
So you might want to look at the histogram or unique-colors to see how many actual colors exist.
convert logo: -transparent white -alpha extract -format "%[colors]\n" info:
2
Through some agonizing searching and trial and error, I may have figured it out. If I run
convert rose: -channel A -separate -format %[fx:z] info:-
I get the number of bits in the alpha channel. For PNGs it seems to print 8, for JPEGs and GIFs it prints 1.
I have a png whose width is 2551 pixels and whose height is 3578 pixels.
On this png, I use the -crop option of convert to cut out an image whose dimensions are 2362 x 3389 pixels:
convert original_2551x3578.png -crop 2362x3389+94+94 crop_2362x3389.png
This works as intended.
Then, I use convert to create a jpg:
convert crop_2362x3389.png -format jpg -flatten -background white out.jpg
I expected this command to produce a jpg with the same dimension (2362 x 3389). Much to my surprise, the produced jpg has the dimension 2551 x 3578 pixels (which is the same as the original image).
So it seems that somehow the original size is stored along with crop_2362x3389.png.
How can I use convert to convert a png into a jpg and have it keep the dimension of crop_2362x3389.png?
The reason you are seeing this is that when you do your initial crop, the image "remembers" it was part of a larger image and where in that image it used to be.
You can see this if you do your original crop and then run identify and look at the 4th field, just left of 8-bit.
convert original_2551x3578.png -crop 2362x3389+94+94 crop_2362x3389.png
You can also tell ImageMagick to "forget" it by using +repage like this:
# Repage after changing geometry to forget earlier geometry
convert original_2551x3578.png -crop 2362x3389+94+94 +repage crop_2362x3389.png
# Check IM has forgotten image used to be a part of a bigger one
identify crop_2362x3389.png
crop_2362x3389.png PNG 2362x3389 2362x3389+0+0 8-bit sRGB 256c 15.1KB 0.000u 0:00.000
Ok, I've found a solution. The geometry after the -crop parameter must be followed by a !:
convert original_2551x3578.png -crop 2362x3389+94+94! crop_2362x3389.png
This works as intended.