Task on basic_image_operations

Task on basic_image_operations

Task details :

Task 4.1

?? Create image by yourself Using Python Code 

?? Task 4.2

?? Take 2 image crop some part of both image and swap it. 

?? Task 4.3

?? Take 2 image and combine it to form single image. For example collage 

Task 4.1:

hello everyone!

I have uploaded my task code on github and has shared you the link in the description area here i will only be showing the final image i have created using cv2 module :

I have made an image of hut :

No alt text provided for this image

Task 4.2 :

Here i have cropped both the images and swapped them :

Image1:

No alt text provided for this image

Image 2:

No alt text provided for this image

Image_1_new:

No alt text provided for this image

Image_2_new:

No alt text provided for this image

Task 4.3:

Here i had used PIL library from python to do the task it can be done using other desired libraries:

import Image module using:

from PIL import Image

I have downloaded two images from internet and saved them in the current folder so that i don't have to provide the path of images .To open the images type:

image1 = Image.open('badrinath-dham1.jpg')
image2 = Image.open('Kedarnath.jpg')

To see the images:

image1.show()
No alt text provided for this image

similarly for image 2

image2.show()
No alt text provided for this image

NOTE:for merging two photos in one picture we have first have to make sure that both images are of same size , therefore to check the size:(Refer github link)

image1.size
#and
image2.size

since in my case size of my images are not equal therefore i have to resize the image for equal size using:(NOTE: here (454 , 350) is the size of image1 ,where 454 is number of rows and 350 is number of columns present in the image.And i m resizing the image2 to this size so that i don't have any problem in merging them.

image2 = image2.resize((454 , 350))

Now since we have both the images ready with same size we have to put them together in one image and for that we first have to create an empty box where we can hold both the images. Also note that we have to provide the width of the box 2 times the width which is used for one box so that we can store both the images . If dont do so then inspite of merging the images together only one image will be shown. In the command below 'RGB' is the mode of pixel and (250,250,250) is the ratio in which we filled RGB colours. You can use any ratio of your choice??

new_image = Image.new('RGB',(2*image1.size[0], image1.size[1]), (250,250,250))

Now since we have box ready we can now paste both the images :

new_image.paste(image1) 
#This will paste the image1 to the left most corner by default)
new_image.paste(image2,(image1.size[0],0))
#This will add image2 with image1 and here we also have to tell that image1 is already there in left part of the box that is on first column represented by 0 index number.

now the process is done and we can save the image using:

new_image.save("merge.jpg","JPEG")

To see the image:

new_image.show()
No alt text provided for this image

I have swap the images in the same process using :

image_swap = new_image.transpose(Image.FLIP_LEFT_RIGHT)

New final image:

No alt text provided for this image


要查看或添加评论,请登录

Anuj Ramola的更多文章

社区洞察

其他会员也浏览了