speed up imagemagick file conversion to monochrome image - imagemagick

$ file in.jp2
in.jp2: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 3560x4810, components 3
I use the following command to convert a .jp2 file to a monochrome pdf file. But it takes 20 seconds to convert a file.
convert in.jp2 -threshold 75% -type bilevel -monochrome -compress Zip out.pdf
Is there a way to speed up the conversion without losing any resolution and increasing the output file size?

Related

Any file type that can go over JPEG maximum resolution limit?

I am trying to combine multiple JPEG file into one single long file using this command
magick convert ..\galerry\*.jpg -gravity center -append longview.jpg
However while combining the files, imagemagick reached the limit of 65500 pixels
Is there any file format that can store image larger than 65500 pixels with the same compression as JPEG file format?

how to convert scanned jpg files to pbm format losslessly?

Using ImageMagick's convert utility to convert some scanned jpg files to pbm files.
However, even if the option -quality 100 is used, the pbm's resolution still looks worse than the original scanned jpg file.
Worse, the scanned jpg file is a colored one, while the converted pbm is black and white.
Info of original jpg:
image size: 2256 × 1568 pixels
dpi: 300 pixels/inch
color model: RGB
info of the converted pbm:
image size: 2256 × 1568 pixels
dpi: 72 pixels/inch
color model: Gray
Currently, here is what I did to convert the format:
qiang#bonjour:~/scan$ convert scan000.jpg scan000.pbm
Am I missing any option to use with convert? As I mentioned earlier, -quality 100 had been tried, but to no avail.
Using ImageMagick, I think you want to output to PPM not PBM. Try
convert image.jpg image.ppm
or try the ascii version by using
convert image.jpg -compress none image.ppm
PBM is binary (black/white) and PGM is grayscale. If you want to keep color, then you need to use PPM.
Unfortunately, I believe that ImageMagick can only read DJVU format images. So you cannot write to it directly from ImageMagick.

Convert images and show result using Image Magick

I am manipulating images using Image Magick. Here is the command that I use:
convert source.png -resize 1200 -quality 75 result.jpg
It works as expected. I am no wondering whether there is a way to report a conversion result showing how much compression has been done (in percentage or kilobyte or just by showing the sizes of original and converted images)?
I have tried -monitor switch, but it only shows a progress kind of report during conversion.
(I am using Linux)
The quality setting you use tells ImageMagick how much to compress the image. Alternately, you can compute the ratio of the output file size by the input size. Or the ratio of the output file size with -quality 75 to that when using -quality 100, even though -quality 100 still compresses some.
You can get the size of the image by
convert image -precision 16 -format "%b\n" info:
Setting a large precision will forces the result to be in Bytes, but you will have to remove the B character from the end. So you can do the following to get the percent of output/input file sizes:
outsize=$(convert output -precision 16 -format "%b\n" info: | sed 's/B//g')
insize=$(convert input -precision 16 -format "%b\n" info: | sed 's/B//g')
percent_size=$(convert xc: -format "%[fx:100*$outsize/$insize]\n" info:)

ImageMagick: reduce image size

I am using ImageMagick to reduce the image resolution, height and width.
I have noticed a few things. When I am changing resolution at "Image Size" through Photoshop (version 7) from 300dpi to 150dpi image height and width automatically change.
With ImageMagick however I am not getting such variations. For example, if image contains 878 width and 179 height at 300dpi, when changing it to 150 dpi, automatically the image width changing to 439 and height 89 respectively.
Can any one support me how to obtain such changes through ImageMagick.
The dpi setting is not really relevant in most imaging applications/areas, until the point at which you want to print an image.
Do you really need to set it? I mean, if you want to half the size of an image, just use ImageMagick and do:
convert input.jpg -resize 50x50% output.jpg
and ignore the dpi.
To resize the image keeping the rendered size the same, you can use the -resample
option, like so:
$ convert original.jpg -resample 150x150 new.jpg
Using your example, if the original is an 878x179 image at 300DPI,
the result is an 439x90 image at 150DPI:
$ file original.jpg
original.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 300x300,
segment length 16, baseline, precision 8, 878x179, frames 3
$ file new.jpg
new.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 150x150,
segment length 16, baseline, precision 8, 439x90, frames 3
You can alternatively use the
-density
option along with the
-resize
option to achieve the same effect:
$ convert original.jpg -density 150x150 -resize 50%x50% new.jpg
In summary:
-density
just sets the DPI metadata without changing the underlying image;
-resize
changes the image size without changing the DPI;
-resample
changes the DPI and resizes the image accordingly.
Uses
The DPI metadata is relevant when you need to print an image or convert it to a PDF.
Now you can convert both images to PDF and get files with essentially the same page size:
$ convert original.jpg original.pdf
$ convert new.jpg new.pdf
$ pdfinfo original.pdf | grep -a "Page size:"
Page size: 210.72 x 42.96 pts
$ pdfinfo new.pdf | grep -a "Page size:"
Page size: 210.72 x 43.2 pts

Resizing an Image using Imagemagick convert

I have a YUV420 image of size 1280x720. I am trying to resize it to 720x576 using convert (Imagemagick) using below commandline options. But the generated output file doesnot seem to be a proper resized YUV420 image(I want the resized output also to be in YUV420 format):
convert -size 1280x720 -depth 8 -sampling-factor 2x2 test_1280x720_yuv420.yuv -filter lanczos -resize 720x576 -depth 8 -sampling-factor 2x2 720x576_yuv420.yuv //Here the output file size is not what it should be of a 720x576 YUV420 file which is 720x576x1.5 bytes.
Qiestion: What is the format of this output file then?
Also tried -sample option as, but same result. Incorrect sized output file. I even tried to display the generated resized file, but it sure is not a YUV420 file, as could not view it correctly at all.
convert -size 1280x720 -depth 8 -sampling-factor 2x2 test_1280x720_yuv420.yuv -sample 720x576 -depth 8 -sampling-factor 2x2 720x576_yuv420.yuv
Question: Would convert be able to do what I am trying to get done? IF yes, what are the options?
Question: Any other tool(freeware,shareware) which could help me resize YUV files(different formats YUV420, YUV444) to YUV format output files?
Try to ignore aspect ration!
Ignore Aspect Ratio ('!' flag)
If you want you can force "-resize" to ignore the aspect ratio and distort the image so it always generates an image exactly the size specified. This is done by adding the character '!' to the size. Unfortunately this character is also sometimes used for special purposes by various UNIX command line shells. So you may have to escape the character somehow to preserve it.
Example:
convert image.gif -resize 64x64\! resized_image.gif //Resized Image with ignore ratio option

Resources