Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
I have almost 200 images (.png files) that I want to assemble together into one PNG file. All the image files have the same dimensions (705 x 1000).
I want to make 20 rows of 10 images each row, with 10 pixels horizontally between each image and 10 pixels between each row.
How can I do this programmatically? Can this be done with Python? Can I avoid having to do this manually using a word-processing or other other office style program?
I did some Googling and found my answer.
The Pillow Python package is exactly what I was looking for.
It can merge images as such:
from PIL import Image
def merge(im1, im2):
w = im1.size[0] + im2.size[0]
h = max(im1.size[1], im2.size[1])
im = Image.new("RGBA", (w, h))
im.paste(im1)
im.paste(im2, (im1.size[0], 0))
return im
(taken from Official Pillow docs)
This is enough to get me started!
With ImageMagick in Terminal, using:
magick montage *.png -tile 10x20 -geometry +10+10 result.png
If Python is a hard requirement, which doesn't seem to be the case from your question, you can use wand which is a Python binding to ImageMagick.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have an image save as pippo.dat , I want read it and work on it, the dimensions of the image are 368 x 600 pixel. How should I do?
I tried to use Numpy.readtxt but it doesn't work. I am a beginner.
Aside from the confusing file extension discussed in the comments; Numpy alone doesn't really support images as such, and trying to use loadtxt on one will just produce a mess if it even works at all.
What we can do is use another library like Pillow that does understand images, and create a Numpy array using that.
firstly you'll need to install Pillow pip install Pillow
from PIL import Image
import numpy as np
# Open the image
image = Image.open('myimage.jpg') # swap name as needed
print("Your image's size is", image.size)
# show the image in a window. You can delete this line if you like.
image.show()
# convert it to a numpy array:
data = np.asarray(image)
And now data is a 3D numpy array of the image, the first 2 dimensions being X and Y pixels, and the 3rd being the colour values ([R,G,B] or [R,G,B,A] if its got an alpha/transparency channel. You can check with image.mode) (if you get a 'weird' palette or grayscale mode like P or L then read this answer: https://stackoverflow.com/a/52307690/9311137 on converting/handling)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am making google's t-rex runner game. So I got a .png file which contains all the fonts, picuters of the t-rex, etc. So I am now having problem in getting a part of the image. Here is the image:
Is there anyway in which I can get a part of the image. I am using python, pygame.
Assuming you know what a Rect and Surface is, here is a way to do it:
def image_at(png, rectangle): # rectangle would be the section you want in the png
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size)
image.blit(png, (0, 0), rect)
return image
(inspired by https://www.pygame.org/wiki/Spritesheet which could be exactly what you were looking for)
Basically you create a surface with the dimensions of your desired section of the png, they you draw (blit) the whole png on your created surface, and that will show only the part you selected throught your rectangle.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Actually I work on a car detection project at real time, when I launch the camera I want to make a screenshot (.png) for any car and save it in a path, which means i need a function in opencv that does the screenshot of just a car detected (not all windows).
Suppose you have the following image:
Now i want to extract to individual images each of the independent cars, like this for example:
And save in path/image_date.png.
Thanks in advance.
Given an image and a bounding box that is determined by your car detector:
cv::Mat image = …;
cv::Rect roi = …; // roi stands for "region of interest"
cv::Mat output = image(roi); // slice the car rectangle out of the image
cv::imwrite("car.png", output);
Note that this operator() will reference the original image data, no data copy will be made. So this is a very efficient way of working on a specific region of interest.
How to best detect the cars in an image in the first place, is too broad for a SO question.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to extract handwritten text from:
using https://cloud.google.com/vision/docs/handwriting
Without using any third party technology, is there any option in Google vision API to remove vertical and horizontal lines from the image before extracting the text?
Hahaha I literally did the exact same thing like 2 months ago.
No, the Vision API can't do this.
Here's how I did it:
1) create an image object with the Python PILLOW library.
2) Get the matrix representation of the image.
3) binarise the matrix.
4) Loop through it line by line and row by row. When you encounter a black pixel, start a counter. If you encounter a white pixel, reset the counter. If the counter goes higher than some high number, conclude that it is a line.
5) Change the black pixels in the line to white pixels.
6) Use Pillow to get a PNG back again.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I would like to transform my RGB image to grayscale image by not using converting function but with the red green blue values . For example, if my image is totally blue, it will be converted to white if I get blue components of it and it will be black if I get red components of my RGB image. It will be done in Python via OpenCV.
Thanks in advance.
The converting function that you are referring to does the same - it weights the R,G and B channel values of each pixel, and takes the sum. Since OpenCV uses the BGR colorspace on reading images, your conversion function will be something like this-
def rgbToGray(img):
grayImg = 0.0722*img(:,:,1) + 0.7152*img(:,:,2) + 0.2126*img(:,:,3)
return grayImg
The specific weights mentioned here are taken from the ITU-R BT.709 standard used for HDTV, developed by the ATSC (https://en.wikipedia.org/wiki/Grayscale)