Primo Raj
Primo Raj

Reputation: 109

How to edit pixel values of color image in SageMath?

I would like to change pixel values in a color image with Sagemath. I can do the same in python, but my program contains some parts which can not be done with python. Here are the codes for SageMath:

MWE:

from PIL import Image
img=Image.open('image.pgm')
pxl=img.load()
#pxls=img.getdata()
print pxl[0,0]  

When I compile thse codes with sage, error occurs :

"  File "smmm.sage.py", line 8, in <module>
    print pxl[_sage_const_0 ,_sage_const_0 ]
TypeError: an integer is required
"  

How can I fix this?

Upvotes: 0

Views: 149

Answers (1)

kcrisman
kcrisman

Reputation: 4402

If you could provide an example with an image we can try out that would be ideal. However, I suspect that if you do

print pxl[int(0),int(0)]  

you might be in good shape. The issue is that pxl might require Python ints, not Sage Integers.

Upvotes: 0

Related Questions