raghibahsan

Untitled

Nov 11th, 2015
2,694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import cv2
  2. import cv2.cv as cv
  3. import numpy as np
  4. import scipy
  5. import Image
  6.  
  7. filename = "image.bmp"
  8.  
  9. oriimage = cv2.imread(filename,0)
  10. k=4
  11. newx,newy = oriimage.shape[1]/k,oriimage.shape[0]/k #new size (w,h)
  12. newimage = cv2.resize(oriimage,(newx,newy))
  13. cv2.imwrite("new.bmp",newimage)
  14. # cv.SaveImage("new.jpg", newimage)
  15. im = cv.LoadImage("new.bmp",0)
  16. k*im.width
  17. c = [[0]*k*im.width for i in range(k*im.height)]
  18.  
  19. # c[][]=[k*im.height][k*im.width]
  20.  
  21. # displaying the matrix form of image
  22. # gray = cv2.cvtCOLOR(im, cv2.COLOR_BGR2GRAY)
  23. # print gray
  24. for i in range(im.height):
  25.     for j in range(im.width):
  26.         # print im[i,j],
  27.         # if(i%2==0):
  28.         c[2*i][2*j]=im[i,j]
  29.         # print c[i][j],
  30.     # print "\n",i,j,  
  31. # Making  a cover image
  32. # Algo is to make a array of the original size say
  33. #   h=k*im.height;
  34. #   l=k*im.width;
  35. # then copy unchanged pixel of im array to array C;
  36. # that is c[i`,j`]=im[i,j]; where i`=2*i,j`=2*j;
  37.  
  38. # for i in range()
  39.  
  40. # scipy.misc.imsave('outfile.jpg', image_array)
  41. np.asarray(c)
  42. ime = Image.fromarray(c)
  43. ime.save("your_file.jpg")
  44.  
  45. cv2.imshow("original image",oriimage)
  46. cv2.imshow("resize image",newimage)
  47. cv2.waitKey(4000)
Advertisement
Add Comment
Please, Sign In to add comment