I started messing around with image processing and I want to make an image matrix, vector (one-dimensional array) and reverse each to image again, this is the code (taken from the example of openCV),In addition - how i will normalize the 1d array ? and what happen after i`m normalize this array, I can make it to image after normalizing?
import cv2.cv as cv
import numpy
img=cv.LoadImage("test3.JPG")
mat=cv.GetMat(img)
a = numpy.asarray(mat)
print a
the output is:
[[[150 150 150]
[171 171 171]
[242 242 242]
...,
[252 252 252]
[252 252 252]
[252 252 252]]
[[151 151 151]
[170 170 170]
[244 244 244]
...,
[252 252 252]
[252 252 252]
[252 252 252]]
[[159 159 159]
[172 172 172]
[248 248 248]
...,
[252 252 252]
[252 252 252]
[252 252 252]]
...,
[[251 251 251]
[251 251 251]
[251 251 251]
...,
[249 249 249]
[248 248 248]
[248 248 248]]
what is the meaning of the three dots, its not printing all the values? this specific image is 125X150
Thanks.
EDIT
import cv2.cv as cv
import numpy
import Image
def normalize(arr):
for i in range(3):
minval = arr[...,i].min()
maxval = arr[...,i].max()
if minval != maxval:
arr[...,i] -= minval
arr[...,i] *= (255.0/(maxval-minval))
return arr
img=cv.LoadImage("test3.JPG")
mat=cv.GetMat(img)
a = numpy.asarray(mat)
b = normalize(a)
print b
with open('1.txt.',"w") as f:
f.write("\n".join(" ".join(map(str, x)) for x in (b)))
im = Image.fromarray(b)
im.save("12.jpeg")