Trying to manipulate images using Python -
i trying learn python, first code have written:
#!/usr/bin/python # filename: read_image.py f=open('1.raw','r+b') image=f.read() f.close() f=open('copy.raw','w+b') f.write(image) f.close() in range(1,256): image[i]=0
in first part reading '.raw' image binary file , making copy of it. part works fine on own , copy of image after execution of code. wish manipulate image, starters trying blacken first line of image, following error:
traceback (most recent call last): file "c:/python32/read_image.py", line 15, in <module> image[i]=0 typeerror: 'bytes' object not support item assignment
i tried using 'int' type variables copying image them, error persists except instead of 'bytes' object not support assignment, 'int' object not support assignment. how should go solving problem?
please note grayscale image, , pixel values range 0 255, tried printing array image on shell , showed me values in range.
if you're trying image processing in python, try python imaging library* (pil) found here: http://www.pythonware.com/products/pil/
[*] keep in mind have use python 2.x opposed 3.x if use library, unfortunately case lot of powerful python libraries.
Comments
Post a Comment