montage: distortion filter on the combined images - imagemagick

I am using the Montage of Image magick to combine all images contained chicont pattern and form 3 row grid composed of the fused images:
montage "${my_images}"/*chicont.png -geometry 1200 -tile x3e -mattecolor DarkGoldenrod2 -mode Frame -distort BarrelInverse 3:30 output_grid.png
By means of the option -distort BarrelInverse 3:30 each combined image is distorted so the combined image would consist of many distorted parts assembled together.
Would it be possible to apply such distortion selectively on some images located in various places of the resulted combined image ? So the expected output image would contain only several distorted images mixed with the images added to the grid without distortion ?

Related

Image magic convert command creates more than one file

I executed below command to convert a .tif file to a .jpg file. But for some tif images it generates 3 jpg files when only one file is expected. One is the expected jpg file, one is the same image in a black background and the other is just a white image.
magick convert /<.tif image name> -intent relative -resize 1500x1500> -quality 95 -colorspace sRGB -strip -auto-orient /<output .jpg image name>
Does anyone know the reason for this? what property of the input file causing this? or is there a issue with the command?
magick convert /<.tif image> -intent relative -resize 1500x1500> -quality 95 -colorspace sRGB -strip -auto-orient /<output .jpg image>
Expect this to give a single jpg image. But it gives 3 images for some input .tif images
Just adding some meat to #GeeMack's comment...
TIFF files often contain multiple images - or IFDs as referred to in the documentation. These can represent many things, but the most common are:
a low-resolution, flattened preview image followed by a full-resolution image aimed at providing quick previews
multiple pages of longer documents
colour separations for printing
the many channels of multi/hyper-spectral images
the layers of a multi-layer images, e.g. Photoshop editing layers
images and their associated masks, or classes/categories/classifications
... and so on.
A quick way to check what you have is with ImageMagick's identify command as that will produce a line for each image in the file, and you can often tell by the sizes, shapes and types of the layers which is a small preview and which is high resolution image, or that there are 242 channels of identical resolution images for a EO-1 hyperspectral imager.
magick identify IMAGE.TIF
Here's an example:
magick identify Prokudin-Gorskii.tif
Prokudin-Gorskii.tif[0] TIFF 3702x3205 3702x3205+0+0 16-bit sRGB 134.955MiB 0.060u 0:00.064
Prokudin-Gorskii.tif[1] TIFF 3702x3205 3702x3205+0+0 16-bit sRGB 134.955MiB 0.000u 0:00.001
Prokudin-Gorskii.tif[2] TIFF 625x175 625x175+841+814 16-bit sRGB 134.955MiB 0.000u 0:00.001
and you can see from the sizes that there are two full layers followed by a reduced size layer that is only annotation or markup on a small area of the image.
Another useful technique is to lay out all the images within a TIFF beside each other in a row across the page, with 10 pixel gaps between, using a command like this:
magick IMAGE.TIFF +smush 10 contents.jpg
We can now see that the three layers in the foregoing image correspond to a flattened version of all the layers on the left, followed by the two individual layers themselves in the centre and the reduced size yellow line overlay layer on the right.
If we then determine that it is only the first, flattened image we are interested in, we can extract and manipulate that alone by adding its sequence number in square brackets afterwards. So, to extract just the first flattened image:
magick IMAGE.TIF[0] extracted.tif
You can also extract multiple individual images and ranges, using commas and dashes.
Note also that magick convert is generally not what you want.
Note also that exiftool is lighter weight than a full ImageMagick installation and can also tell you what's in a multi-IFD TIFF.

Gray scale to text scan image to black/white image with higher resolution

convert 0101.jp2 -threshold 50% -type bilevel -monochrome -compress LZW ../0101.tiff
The resulting image looks jagged when I use the above command to convert a colored scanned text page to a black/white image (must be one bit per pixel). I want to make it of a higher resolution to look smoother. How can I use convert to do so?
Note that SO automatically converts tif image to jpg format so the output image shown below is not the same as the output image. You will need to run the convert command to get the true output image in tif.
If instead of thresholding you apply a strong contrast the gray pixels on the edge remain in a range of grays and the output is not jagged.
convert Original.jpg -sigmoidal-contrast 30 Corrected.jpg
(there are several ways to increase contrast in Magick)

How to fit multiple images in a page optimally using ImageMagick

Suppose I have a bunch of images in a folder with different sizes. The goal is to fit images in a number of pages (e.g. A4) in a way that the whitespace is minimal. There shouldn't be any compression or resizing involved. It is acceptable that some images would be rotated.
Here is what I came up with but doesn't try to "fit" images in any way:
montage *.jpg -mode concatenate -tile 2x2 -page A4 -geometry +20+20 out.pdf
Is it possible using imagemagick and montage switches?
I guess the computational geometry algorithm should change the 2x2 and +20+20 part of the command above, right?
In ImageMagick 7 (7.0.10-23 or higher), there is a new feature for doing collages called Ashlar. But it resizes to fit all the provided images into the space allocated.
See https://imagemagick.org/script/formats.php#pseudo
magick *.jpg -define ashlar:best-fit=true ashlar:canvas.png[1000x1000+5+5]
The [1000x1000+5+5] specifies the output dimensions and the minimum spacing in x and y between images.
Here is A4 size result:
magick *.jpg -define ashlar:best-fit=true ashlar:canvas2.jpg[595x842++0+0]

ImageMagick: montaging image from different-sized tiles

I'm developing a script to download images from tile-based image-hosting.
I downloaded tiles using wget and trying to use montage to compine them.
The problem is that I've got tiles with different sizes (last tile in row is more narrow than the others). Here is combine command:
montage $temp/*.jpg -tile $maxcolumn"x"$maxrow -geometry -1-1 -quality 100% merged.jpg
ImageMagick aligns tiles by grid and produces this image (see right and bottom sides).
image http://leftparagraphs.ru/!/merged.jpg
How do I fix this with montage?
Fixed by specifying "-mode Concatenate".
Also I have to run another instance of convert after montage to "-trim" resulting image.
This solution did not work for me. To combine two different height images into one, I first used the identify command to get the height of the largest image (1280 pixels):
identify large.jpg
Then I used the following command to resize the smaller image and combine it side by side with the larger one:
montage -tile 2x1 -geometry +0+0 small.jpg"[x1280]" large.jpg output.jpg

How to insert one row spacing between tiles in a tiled image using Imagemagick?

I have a bunch of images that I want to tile together in one row. This can be done using Imagemagick montage like this
montage `ls tile*.png` -tile x1 -gravity west -geometry 1x1\<+0+0 out_file.png
However, now I want to insert one pixel of spacing after each tile. I played with -tile-offset -1+0 for a bit but this would not change anything. Similarly, I could use -geometry 1x1\<+1+0, but this would introduce two pixels of spacing instead of one.
How can I do one pixel of spacing between tiles?
If the images are a known size then you can simply do 1 pixel larger in the -geometry switch. So if the images are 256x256 then use -geometry 257x256

Resources