Hi i am using the below code to merge more than one image using PIL module
from PIL import Image
img0 = Image.open("w1.png")
img0 = img0.convert('RGBA')
img1 = Image.open("body.png")
img1 = img1.convert('RGBA')
img0.paste(img1, (0,0), img1)
img0.save('0.png')
img2 = Image.open("0.png")
img2 = img2.convert('RGBA')
img3 = Image.open("d1.png")
img3 = img3.convert('RGBA')
img2.paste(img3, (0,0), img3)
img2.show()
would like to know if there is way i can merge more than two images.
i have 8 images that i need to merge.
Thank you for any suggestion.
would like to know if there is way i can merge more than two images. i have 8 images that i need to merge.
Just... keep paste-ing new images on?
All Image.paste does is merge the parameter image onto the subject, you can keep doing that, and it'll keep merging the new images.
if you want to merge img,I suggesting a tool called stegsolve
There is a download url:
https://github.com/eugenekolo/sec-tools/tree/master/stego/stegsolve/stegsolve
There is usage:
Related
I tried to get the difference of two images. Here are my two images.
However, I only got a blank image like this
I use OpenCV package in python. The code I use is:
image3 = image1 - image2
plt.imshow(image3)
plt.show()
The backgrounds of the two images are not the same. I don't understand why the difference of the two images is just blank. Can someone help me with this?
Thank you in advance.
This works fine for me in Python/OpenCV using cv2.absdiff(). I suggest you use cv2.imshow() to view your results and cv2.imwrite() to save your results.
import cv2
import numpy as np
image1 = cv2.imread('image1.png')
image2 = cv2.imread('image2.png')
diff = cv2.absdiff(image1, image2)
print(np.amin(diff), np.amax(diff))
cv2.imwrite('diff.png', diff)
cv2.imshow('diff', diff)
cv2.waitKey(0)
Result:
Min and Max Values In Diff:
0 91
I've two binary files containing rgb pixes values. I would like to merge these two files into one big file.
I did this first:
img1 = np.fromfile("img1.rgb",dtype=np.uint8)
img2 = np.fromfile("img2.rgb",dtype=np.uint8)
img1 = np.reshape(img1,(1024,10000,3))
img2 = np.reshape(img2,(1024,10000,3))
out = np.empty((1024,20000,3))
out[:,:10000] = img1
out[:,-10000:] = img2
out.flatten().tofile("out.rgb")
The problem is that I load in memory the 2 images and also the resulting merge image.
Is it possible to do this without loading the images into memory ?
Maybe by using numpy memmap?
I Want to Vertically stack the images through a loop, I am having an image out of the loop to that image I want to add the images vertically through a loop in python
Required Output format,
Output what I am getting
image=cv2.imread(os.path.join(root,os.path.join(root,Value[0][0:3][1])))
for a in Value[0][3::]:
image1 = cv2.imread(os.path.join(root, os.path.join(root, a[1])))
numpy_vertical = np.vstack((image, image1))
cv2.imshow('Numpy Vertical', numpy_vertical)
it would be very helpful if someone helps me
Try this:
numpy_vertical=cv2.imread(os.path.join(root,os.path.join(root,Value[0][0:3][1])))
for a in Value[0][3::]:
image1 = cv2.imread(os.path.join(root, os.path.join(root, a[1])))
numpy_vertical = np.vstack((numpy_vertical, image1))
cv2.imshow('Numpy Vertical', numpy_vertical)
otherwise you're overwriting just stacked images again and again with the new image.
I'm working on an image processing project. I have 2 RGB images and I would like to create a new one by overlapping the 2 input images.
This is my 2 input images:
I'm using the cv2 "add" method to achieve this. But the result is not the hoped result...
The result is as follows:
I don't want to have a transparency on my red stripe. I would like something opaque, which covers the crack on the image 1.
There is my code:
img1 = cv2.imread(r"C:\Users\francois.bock\Desktop\crack.jpg")
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
img2 = cv2.imread(r"C:\Users\francois.bock\Desktop\line.png")
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
# Adding two images
add = cv2.add(img1, img2)
#Display the image
img = PImage.fromarray(add)
img.show()
I also naively tried to add the 2 images like that:
add = img1 + img2
add = add.astype(np.uint8)
But the result is even stranger.
I also used the cv2 "addWeighted" method, but it also gives a transparent stripe.
So my question is, is there a simple way to add 2 images without transparency? Thank you in advance.
You can do it with straight Numpy:
import numpy as np
import cv2
a = cv2.imread('a.jpg')
b = cv2.imread('b.png')
# Make "a" red anywhere b>0
a[ np.any(b>0,axis=-1) ] = [0,0,255]
If you happen to have blue and green or any other colour lines lurking in your image too, you can use this:
# Anywhere image "b" is not black, use image "b", else use image "a"
result = np.where(np.any(b>0,axis=-1,keepdims=True), b, a)
I am having 3 to 4 images and I am trying to combine them all into one image (put into one window) and then show them through CV2.imshow() function. But the problem is that every solution to this problem is for exactly the same dimension images, which is not my case. My images are all of different dimensions. Kindly help me out how to solve this problem? I have four images with different dimension and want output like this
|||||||||||||||||||||||||||||||||
|| Image1 || Image2 ||
||||||||||||||||||||||||||||||||||
|| Image1 || Image2 ||
||||||||||||||||||||||||||||||||||
Currently, I have code like this for two images which work on only equally sized Images
im = cv2.imread('1.png')
img = cv2.imread('2.jpg')
both = np.hstack((im,im))
cv2.imshow('imgc',both)
cv2.waitKey(10000)
Use im.resize() function of opencv to resize the image and then do the combining task.
Always use a reference dimension such as 1000 x 800 (you can change it)
import cv2
import numpy as np
list_of_img_paths = [path2,path3,path4]
im = cv2.imread(path1)
imstack = cv2.resize(im,(1000,800))
for path in list_of_img_paths:
im = cv2.imread(path)
im = cv2.resize(im,(1000,800))
# hstack to join image horizontally
imstack = np.hstack((imstack,im))
cv2.imshow('stack',imstack)
cv2.waitKey(0)