How to reposition or combine multiple images into a single image? - image

I have around 600 png files that are tiled or grid maps of a big location. These maps are named with numbers they receive according to their location. The maps intersect each other around 50 pixels. How do i combine them to form a single big map? The images has same resolution and approximately same sizes. All the images are the part of big image. I have used photoshop's photomerge but that is time consuming for large number of images.
My main objective is to create a large sized map with undiminished quality.

Related

Finding the number of pixels with no value for multiple images

I have 677 LANDSAT images and many of them are missing data for some pixels. I am trying to figure out how many pixels have no data for each image (or how many pixels have values for each images) so I can exclude images with less than 30% coverage. My images are in TIFF format.

find difference of 2 images that may also be different sizes

I have 2 pdf files that have multiple layers of images.
The images are black and white diagrams and should be almost identical.
Problem is that the position of the diagrams in the canvas may be offset by a little (>3%) and they may be scaled to slightly different sizes, the size difference is small (>3%)
Is there a way to manipulate the images to minimise their difference by translation and scaling and then highlight the differences?

How to produce a unitary thumbnail for a billion of png images?

In the application, there are about 1 billion of png images (size 1024*1024 and about 1MB each), it needs combining the 1 billion images to a huge image, then produces a size 1024*1024 unitary thumbnail for it. Or maybe we don't need to really combine the images to a huge one, but just do some magic algorithm to produce the unitary thumbnail in the computer memory? Meanwhile this process needs to be done as fast as possible, better in seconds, or at least in a few minutes. Does anyone have idea?
The idea of loading a billion images into a single montage process is ridiculous. Your question is unclear, but your approach should be to determine how many pixels each original image will amount to in your final image, then extract the necessary number of pixels from each image in parallel. Then assemble those pixels into a final image.
So, if each image will be represented by one pixel in your final image, you need to get the mean of each image which you can do like this:
convert image1.png image2.png ... -format "%[fx:mean.r],%[fx:mean.g],%[fx:mean.b]:%f\n" info:
Sample Output
0.423529,0.996078,0:image1.png
0.0262457,0,0:image2.png
You can do that then very fast in parallel with GNU Parallel, using something like
find . -name \*.png -print0 | parallel -0 convert {} -format "%[fx:mean.r],%[fx:mean.g],%[fx:mean.b]:%f\n" info:
Then you can make a final image and put the individual pixels in.
Scanning even 1,000,000 PNG files is likely to take many hours...
You don't say how big your images are, but if they are of the order of 1MB each, and you have 1,000,000,000 then you need to do a petabyte of I/O to read them, so even with a 500MB/s ultra-fast SSD, you will be there 23 days.
ImageMagick can do that:
montage -tile *.png tiled.png
If you don't want to use an external helper for whatever reason, you can still use the sources.
Randomized algorithm such as random-sampling may be feasible.
Considering the combined image is so large, any linear algorithm may fail, not to mention higher complexity method.
By calculations, we can infer each thumbnail pixel depend on 1000 image. So a single sampling residual does not affect the result much.
The algorithm description may as follow:
For each thumbnail pixel coordinate, randomly choose N images which on the correspond location, and each image sampling M pixels and then calculate their average value. Do the same thing for other thumbnail pixels.
However, if your images are randomly combined, the result is tend to be a 0.5 valued grayscale image. Because by the Central Limit Theorem, the variance of thumbnail image pixel tend to be zero. So you have ensure the combined thumbnail is structured itself.
PS: using OpenCV would be a good choice

Image resizing method during preprocessing for neural network

I am new to machine learning. I am trying to create an input matrix (X) from a set of images (Stanford dog set of 120 breeds) to train a convolutional neural network. I aim to resize images and turn each image into one row by making each pixel a separate column.
If I directly resize images to a fixed size, the images lose their originality due to squishing or stretching, which is not good (first solution).
I can resize by fixing either width or height and then crop it (all resultant images will be of the same size as 100x100), but critical parts of the image can be cropped (second solution).
I am thinking of another way of doing it, but I am sure. Assume I want 10000 columns per image. Instead of resizing images to 100x100, I will resize the image so that the total pixel count will be around 10000 pixels. So, images of size 50x200, 100x100 and 250x40 will all converted into 10000 columns. For other sizes like 52x198, the first 10000 pixels out of 10296 will be considered (third solution).
The third solution I mentioned above seems to preserve the original shape of the image. However, it may be losing all of this originality while converting into a row since not all images are of the same size. I wonder about your comments on this issue. It will also be great if you can direct me to sources I can learn about the topic.
Solution 1 (simply resizing the input image) is a common approach. Unless you have a very different aspect ratio from the expected input shape (or your target classes have tight geometric constraints), you can usually still get good performance.
As you mentioned, Solution 2 (cropping your image) has the drawback of potentially excluding a critical part of your image. You can get around that by running the classification on multiple subwindows of the original image (i.e., classify multiple 100 x 100 sub-images by stepping over the input image horizontally and/or vertically at an appropriate stride). Then, you need to decide how to combine your multiple classification results.
Solution 3 will not work because the convolutional network needs to know the image dimensions (otherwise, it wouldn't know which pixels are horizontally and vertically adjacent). So you need to pass an image with explicit dimensions (e.g., 100 x 100) unless the network expects an array that was flattened from assumed dimensions. But if you simply pass an array of 10000 pixel values and the network doesn't know (or can't assume) whether the image was 100 x 100, 50 x 200, or 250 x 40, then the network can't apply the convolutional filters properly.
Solution 1 is clearly the easiest to implement but you need to balance the likely effect of changing the image aspect ratios with the level of effort required for running and combining multiple classifications for each image.

JPEG-2000: Can I dynamically resize an image without resampling?

One of the nice features of JPEG 2000 is that it's easy to downres an image -- just feed out fewer bytes.
Is there a similar way to scale the image, such that I could send a thumbnail using bytes in the full-size file, without resampling?
No, to resize you will still have to read the original size, resample to the new size, and then recompress.
You can write your file such that it has layers with powers-of-2 sizes, with a very small relative incremental increase in size, and extract those layers.

Resources