I'm trying to convrt RAW image to PNG with Imagemagick.
Imagemagick version I'm using is 6.7.8-9.
The RAW image want to convert is:
https://drive.google.com/file/d/1V1c-ytjkLaCM3KbAc6Yxj2nfWzNkYohc/view?usp=sharing
My client gave me a big RAW image which contains more than 1000 RAW images and it is generated from Dicom. Firstly, I cropped just one image with the command (crop command did not work somehow, so used convert):
convert -size 512x512 -depth 16 UYVY:original.raw result.raw
result.raw appears good on ImageJ.
Now, I have no idea how to get PNG from it.
I tested some commands:
This one generated a very bad quality:
convert -size 512x512 -depth 16 gray:result.raw result.png
This one gets green-ish image:
convert -size 512x512 -depth 16 uyvy:result.raw result.png
If I open result.raw on ImageJ and save as PNG, it works perfectly.
I got an answer from Imagemagick community. Firstly, below code to get the first image from the original raw was wrong.
convert -size 512x512 -depth 16 UYVY:original.raw result.raw
This is the correct way (512*512*2bytes=524228)
head --bytes 524288 original.raw >firstimage.raw
Then convert to PNG:
magick -size 512x512 -depth 16 gray:firstimage.raw -evaluate AddModulus 50% -auto-level x.png
Here is another way in ImageMagick that I think is more intuitive to your signed raw data. I simply specify the data is signed using -define quantum-format=signed. Then stretch the result to full dynamic range using -auto-level.
convert -size 512x512 -depth 16 -define quantum:format=signed gray:original.raw -auto-level result.png
If using ImageMagick 7, then replace convert with magick.
Related
I want to use imagemagick to crop an image.
However, imagemagick will be receiving the image data to crop through a pipe before it:
exiftool -b -RawThermalImage image1.jpg | convert .....-crop.....
I am not sure what to put in the ".....-crop.....", to crop the image data received to a specific area. Please guide.
Usually, after convert, an image is specified for cropping like:
convert rose: -crop 1x1+3+3 cropped.gif
But, in this case, I am confused as to how to complete this command given that the image is coming in from the pipe.
ImageLink:
https://drive.google.com/file/d/14h3z0yFK_9_f2puzbhLUm3D50MDMMnu2/view?usp=sharing
Updated Answer
It transpires that the problem was caused by inadvertently using GraphicsMagick rather than ImageMagick.
Original Answer
You should be able to use a dash - to refer to the stdin if that stream has a well-known magic number (signature) at the start:
exiftool -b -RawThermalImage image1.jpg | convert - -crop ... result.jpg
If the stream is raw, or doesn't have a known magic number/signature, you will need to give ImageMagick a hint, so if it is raw greyscale 8-bit data with shape 640x480, use:
exiftool -b -RawThermalImage image1.jpg | convert -size 640x480 -depth 8 GRAY:- -crop ... result.jpg
If it's RGB888 data with size 80x80, use:
exiftool -b -RawThermalImage image1.jpg | convert -depth 8 -size 80x80 RGB:- -crop ... result.jpg
I'm using Magick's convert tool to convert and combine all my images into PDF.
magick convert *.png -page a4 out.pdf
The resolution of the images are 1079 x 1397
The images in the generated PDF file are off-centered. There's some white space on the top of each page.
Here's a screenshot : https://i.imgur.com/EpvxZNU.png
I don't want to "fill" the entire page with my image. I want to simply "fit" the image the way it has in the screenshot above, BUT be centered (have equal whitespace on the top and bottom)
I don't believe that you can center with -page in ImageMagick 7 unless you do inline computations using the actual desired A4 size in pixels (592x842) via distort and its viewport setting. See page sizes in pixels at https://imagemagick.org/script/command-line-options.php#page
In ImageMagick 7, you should use magick and not magick convert. The latter will emulate ImageMagick 6. However there is a bug currently in ImageMagick 7. The following command works fine with convert in ImageMagick 6, but fails with magick in ImageMagick 7. But it works fine with magick convert in ImageMagick 7.
magick convert *.jpg -virtual-pixel white -set option:distort:viewport "592x842-%[fx:(592-u[t].w)/2]-%[fx:(842-u[t].h)/2]" -distort SRT 0 +repage result.pdf
Here is a simple example:
Input Images:
magick convert lena.jpg barn.jpg -virtual-pixel white -set option:distort:viewport "592x842-%[fx:(592-u[t].w)/2]-%[fx:(842-u[t].h)/2]" -distort SRT 0 +repage result.pdf
Result:
I'm trying to apply watermark on an image using the following imagemagick command
convert input.png watermark.png.png -gravity northwest -composite output.png
The input png file size is 16KB and the watermark file size is 900bytes, but when I executed the above command to apply a watermark, the output png size is 61KB which is almost 4X the size of the original input png file. Is there any better way of applying a watermark to an image file with much better result in terms of output filesize
Test Image: https://res.cloudinary.com/deks86ilr/image/upload/v1533015495/1_rnpbye.png
Test watermark: https://res.cloudinary.com/deks86ilr/image/upload/v1533015494/2_usmonh.png
Here are my results of processing of your images with my PNG8 output using ImageMagick 6.9.10.8 Q16 with libpng 1.6.34.
I note that your input image was type palette, which means it is 8-bits of color per pixel and not 24-bit color. So it is already a low quality image.
Input (~16 KB):
Watermark Image (white on transparency -- so it is invisible here):
Convert to 24-bit PNG:
convert input.png watermark.png -gravity northwest -compose over -composite input_with_watermark.png
I see no significant visible quality loss but the output is now increase from 16 KB to 60 KB. But you can use tools such as pngcrush to compress it further.
Convert to 8-bit PNG:
convert input.png watermark.png -gravity northwest -compose over -composite PNG8:input_with_watermark2.png
The file size is now back to about 16 KB. But as you note the quality is a little poorer. This is likely because the input image (at 8-bits and has 217 colors) was first read back to 24-bits, then watermarked, which included new shades of white and then quantized back to 8-bits, but contains only 84 colors colors.
Another way is to add +dither -colors 256 to the command (the +dither turns off dithering):
convert 1_rnpbye.png 2_usmonh.png -gravity northwest -compose over -composite +dither -colors 256 PNG8:watermark3.png
This is a bit better, since it now uses 189 colors and still has a file size of 16 KB.
One final method is to save the colors from your input to a colortable image. Then use -remap to recolor the output using that colortable:
convert 1_rnpbye.png -unique-colors colortable.gif
convert 1_rnpbye.png 2_usmonh.png -gravity northwest -compose over -composite +dither -remap colortable.gif PNG8:watermark4.png
This results in 8-bit output with 227 colors and still a file size of about 16 KB. So it has a few more colors than your input and visually looks about the same quality as your input.
If you cannot reproduce these results, then perhaps you should upgrade either or both ImageMagick and libpng.
I want to watermark an image, so I used compose multiply, but for some reason it doesn't work as expected.
The command:
magick image.jpg over.png -compose multiply -resize 2048x2048 -gravity center -quality 65 -strip -composite out.jpg
The over.png get inverted first and then applied??
If use the same command with and older version of Imagemagick (x32 6.7.6-1 2012-03-17 Q16) I get the expected results.
This was tested with x64 ImageMagick 7.0.5 Q16 under Windows 10.
Ah it seems I can't post all the images.
After a lot of research, turns out it's an artifact of one of the images being a JPEG in CMYK colorspace.
Very weird, but there you go.
Adding '-profile sRGB.icc' to the line should take care of it.
FYI your syntax is not proper. You have separated -compose multiply and -composite with -resize. You should do it this way with nothing between them.
magick image.jpg over.png -gravity center -compose multiply -composite -resize 2048x2048 -strip -quality 65 out.jpg
As you said there will be issues if your input JPG is CMYK and your png will always be sRGB. So you do need to convert the CMYK to sRGB before processing.
I have a 32 bit single channel EXR image that I want to crop using ImageMagick, the problem is after I crop it it got saved into 32 bit 3 channel image by ImageMagick.
Below are the attempts that I tried that didn't work
mogrify -crop 200x100+238+200 test.exr -colorspace Y
This returns error mogrify: unrecognized image colorspace `Y'.
mogrify -crop 200x100+238+200 test.exr -channel Y
This returns 32 bit 3 channel image.
mogrify -crop 200x100+238+200 test.exr -separate
This returns 8 bit 1 channel image.
I am on Ubuntu 16.04 and my version of ImageMagick is 6.9.6-4 Q32 x86_64.
How can I make ImageMagick to save my EXR file with the original single channel 32 bit format?
One expert from the ImageMagick forum actually posted an answer which works perfectly for me.
convert test.exr -crop 200x100+238+200 +repage -define exr:color-type=Y result.exr