I have 2 tiff files which use the EPSG:32637 coordinate system. I want to clip their intersection region and save it separately as tiff files.
As a result, the output tiff files have the same upper_left and lower_right coordinates and the same size. Can you suggest ways to get the intersection and save them in separate tiff files??? I don't know how to do this.
Get the boundarys of the tifs as a Polygon with this Worfklow.
Get intersection with the Tool Intersection (native:intersection)
Clip the tifs gdal:cliprasterbymasklayer
All the tools you need you'll find in the QGIS processing-Toolbox!
For future GIS-Questions you should ask here.
Related
I have a folder of multiple png images of the same map. The map is on country level and consists of administrative polygons. I have the geojson for this and I want to georeference programmatically, with Python, all of these images to the geojson and then get the color value for each polygon.
An example of the images is this:
and the geojson for this map is available here. I have read about overlay with rasterio but it seems too complicated to rasterize my polygons and back and forth. I also read about georeferencing the polygon corners but this still is about png over tiff file.
Any ideas on how to approach this?
I have a large .tiff raster (at least 200x150), but I need a bunch of 32x32 .tiff files. Is there an easy way to cut up that .tiff in Python? I think the workflow would look something like:
Create 32x32 box in bottom right corner of raster
Clip raster with that box, saving new clipped .tiff raster
Shift box left by 32 pixels (if less than 32 pixels left, shift up 32 pixels and restart on right side)
Repeat clip/shift until can't shift up or sideways
The input raster won't be an even multiple of 32, but I don't care if I lose some of the original raster off of the sides. As long as the original data is preserved for each 32x32 raster, I'm happy.
I was able to solve this using the arcpy module.
The arcpy.management.SplitRaster() documentation is available at https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/split-raster.htm. After this, I used os.listdir() to get a list of the output files. OpenCV has a ndarrayt.shape() function that gives the dimensions of the image, so I looped that over each file and deleted any that didn't match the size that I wanted.
I want to compare two images (.png format) pixel by pixel using selenium in python. Or how could i do it using pillow library.
I have a base image and i get the compare image by taking screenshot of the webpage. I want to compare those two images and assert that they are equal. how can I do it.
Below is what I have tried:
def assert_images_are_equal(base_image, compare_image):
with open(base_image, 'rb') as f1, open(compare_image, 'rb') as f2:
base_image_contents = f1.read()
compare_image_contents = f2.read()
assert base_image_contents == compare_image_contents
But this doesnt work always. I want to compare pixel by pixel. Could someone help me with this using pillow library or any other library apart from PIL? thanks.
It is rather difficult to say whether 2 images are the same or similar, because it depends on your definitions of "same" and "similar".
You can make a solid red image, save it as a PNG and then save the exact same image again and it could be different because the PNG format contains a timestamp in the image header that may have ticked over to the next second in between saves.
You can make a solid red PNG file that is 8-bits deep, and another that is 16-bits deep and you cannot see the difference but the data will be grossly different.
You can make a TIF file in Motorola byte order and the same file in Intel byte order. Visually, and in calculations, they will be indistinguishable, but the files will be grossly different.
You can make a GIF file that is red and it will look no different from a PNG file but the files will differ.
You can make a palette image and a true-colour image and the pixels will be grossly different but they will look identical.
You could make a simple black image with a white rectangle in the middle and write it using one JPEG library and it will come out different from the same image written with a different JPEG library, or even a different release version of the same library.
There are many more cases...
One a more helpful note, you may want to look at Perceptual Hashing which tells you if images look pretty similar. One library that does Perceptual Hashing is ImageMagick and it has a Python binding here and here.
I have a local directory full of geotiff files which make up a map of the UK.
I'm using mapnik to render different images at various locations in the UK.
I'm wondering what is the best way to approach this?
I can create a single RasterSymbolizer then loop through the tiff directory and add each tiff as a seperate layer, then use mapniks zoom_to_box to render at the correct location.
But would this cause the rendering time to be unnecessarily slow? I have no information on how the tiles fit together (other than the data in each individual tiff of course).
I imagine there may be a way to setup some kind of vector file defining the tiff layout so I can quickly query that to find out which tile I need to render for a given bounding box?
You can either generate a big tiff file from the original tiffs with gdal_merge.py (you can find it in the python-gdal package on Debian or Ubuntu) or create a virtual file that mixes them all with gdal_merge-vrt. This second option saves space but probably is slower.
I have a script to save between 8 and 12 images to a local folder. These images are always GIFs. I am looking for a python script to combine all the images in that one specific folder into one image. The combined 8-12 images would have to be scaled down, but I do not want to compromise the original quality(resolution) of the images either (ie. when zoomed in on the combined images, they would look as they did initially)
The only way I am able to do this currently is by copying each image to power point.
Is this possible with python (or any other language, but preferably python)?
As an input to the script, I would type in the path where only the images are stores (ie. C:\Documents and Settings\user\My Documents\My Pictures\BearImages)
EDIT: I downloaded ImageMagick and have been using it with the python api and from the command line. This simple command worked great for what I wanted: montage "*.gif" -tile x4 -geometry +1+1 -background none combine.gif
If you want to be able to zoom into the images, you do not want to scale them. You'll have to rely on the image viewer to do the scaling as they're being displayed - that's what PowerPoint is doing for you now.
The input images are GIF so they all contain a palette to describe which colors are in the image. If your images don't all have identical palettes, you'll need to convert them to 24-bit color before you combine them. This means that the output can't be another GIF; good options would be PNG or JPG depending on whether you can tolerate a bit of loss in the image quality.
You can use PIL to read the images, combine them, and write the result. You'll need to create a new image that is the size of the final result, and copy each of the smaller images into different parts of it.
You may want to outsource the image manipulation part to ImageMagick. It has a montage command that gets you 90% of the way there; just pass it some options and the names of the files in the directory.
Have a look at Python Imaging Library.
The handbook contains several examples on both opening files, combining them and saving the result.
The easiest thing to do is turn the images into numpy matrices, and then construct a new, much bigger numpy matrix to house all of them. Then convert the np matrix back into an image. Of course it'll be enormous, so you may want to downsample.