lundi 2 mars 2015

Stitching images together Opencv -Python

My program takes in an image and crops the image into seperate images according to the scale parameter, e.g. scale = 3 produces 9 images of equal size. I then work out mean rgb of each cropped image and set all pixel values in the image equal to the mean rgb value.


I am wondering how I can stich the cropped images back together to output one image?


Here is my code:



# import packages
import numpy as np
import cv2
import dateutil
import llist
from matplotlib import pyplot as plt
import argparse

#Read in image
img = cv2.imread('images/0021.jpg')

scale = 3
#Get x and y components of image
y_len,x_len,_ = img.shape

mean_values = []
for y in range(scale):
for x in range(scale):
#Crop image 3*3 windows
cropped_img=img[(y*y_len)/scale:((y+1)*y_len)/scale,
(x*x_len)/scale:((x+1)*x_len)/scale]

mean_val=cv2.mean(cropped_img)
mean_val=mean_val[:3]
#Set cropped img pixels equal to mean RGB
cropped_img[:,:,:] = mean_val

cv2.imshow('cropped',cropped_img)
cv2.waitKey(0)

#Print mean_values array
#mean_values.append([mean_val])
#mean_values=np.asarray(mean_values)
#print mean_values.reshape(3,3,3)

Aucun commentaire:

Enregistrer un commentaire