Finding the number of pixels with no value for multiple images - pixel

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.

Related

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?

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.

What's the smallest image format for randomly sized uniformly coloured images?

Without going into much detail, I'm trying to do an HTTP POST of a dummy image to a server to cause the server to create an internal record of the image in its database. The image is to later be replaced in storage with the actual image that's supposed to be there without the server knowing.
Unfortunately, this server is "smart" and validates whatever image data is being sent to it; it will reject random bytes if they don't match some image format (e.g. jpeg, gif, png. etc).
Naturally, the most obvious approach would be to send the smallest gif possible (1x1 grey pixel; ~26 bytes). Unfortunately, this server keeps an immutable record of the dimensions of the image that it reads... so a 1x1 pixel image won't cut it.
So my question is, what's the smallest possible scaled image of a solid colour I can send as a dummy instead? Ideally, a completely uniformly grey image of 100x100 pixels in this format should be roughly the same as a 1000x2000 image of the same colour, due to compression.
(Forgive me if the tags aren't very good; I'm not sure where this should go)
You can possibly achieve what you want with a specially-crafted GIF file.
The GIF format allows you to specify "logical screen width" and "logical screen height" values in the "Logical Screen Descriptor" section at the start of the file, which define the size of the image.
However, you don't actually need to encode the pixels for the entire image, and any pixels which are not encoded are considered transparent. Instead, the GIF file contains one or more "Image Descriptor" sections, which encodes the pixels for a sub-region of the image. This is used for compressing GIF animations (only the sub-regions of the image that change compared to the previous frame need to be encoded) but it can also be used for single-frame images. So what you can do is just output a single Image Descriptor encoding a 1x1 transparent pixel region of the image, and set the logical screen width and height values your desired image size, to create a uniformly transparent GIF image of arbitrary size, for a fixed file size (42 bytes).
You just need to modify bytes 6-9 (for the width) and bytes 10-13 (for the height) of this transparent 1x1 pixel GIF. Note that GIF uses little-endian byte order.
Here is an example file, a 1024 x 1024 pixel transparent GIF image.
This file loads up correctly for me as a 1k by 1k transparent image in the GIMP image editor, but some file viewers seem to base the image size on the size of the image descriptors and display it as 1x1 pixels, which is wrong AFAIK. You'll have to test whether your server reads them correctly.

How to reposition or combine multiple images into a single 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.

Is there an image format suitable for compressing images that only contain a few colors?

I have an image of a cartoon, which only has 4 colors (when not anti-aliased).
Is there an image format that analyses the color palette of the image, and compresses it heavily because it only has a few colors? Something like dynamic palette image compression.
Such an image format will be useful in cases when there are only a few colors in the image.
The header of the image data should specify the colors used in the image and name them say 0,1,2,3
So now the 2d matrix of image color will contain only 2 bit values which was display a 16 bit value previously. But can display the image without any loss.
Image format depends on many things (eg. size, number of colours, device viewing it), just picking it by the number of colours might not give you the smallest/most useable image.
Here is a wiki article comparing many: http://en.wikipedia.org/wiki/Image_file_formats.
Whilst that wiki doesn't give you a format that will only do 4 colours, one of the better suggestions is probably using PNG as this has support for different sized palettes:
"The PNG file format supports 8 bit paletted images (with optional transparency for all palette colors) and 24 bit truecolor (16 million colors) or 48 bit truecolor with and without alpha channel - while GIF supports only 256 colors and a single transparent color." - from wiki

Resources