From Python you can manipulate the pixels of an image. Example 1:
Retrieve pixel value of row=417 and col=459
import arr
img = GetImageMatr('Image') # on RGB images use Image.I to retrieve intensity plane
ROWS,COLS = img.dim()
print 'image size ',ROWS,COLS
row = 417 # row is x when measuring with pixels as reference system
col = 459 # column is y
pixel = img[row*COLS+col]
print ' row, column, value ',row,col,pixel
ScorpionImage class simplifies image pixel access
def CreateScorpionImage(rows,cols):
import arr
class ScorpionImage:
def __init__(self,rows=0,cols=0):
if rows * cols > 0:
self.im=arr.uint8Mat(rows,cols)
# return number rows in image
def Rows(self):
R,C = self.im.dim()
return R
# return number columns in image
def Columns(self):
R,C = self.im.dim()
return C
# transfers image to scorpion image by name
def SetImageMatr(self,name):
SetImageMatr(name,self.im)
# reads scorpion image to class
def GetImageMatr(self,name):
self.im = GetImageMatr(name)
# resets image to zero
def Reset(self):
arr.setArr(self.im,0)
# set pixel of image to value
def Set(self,row,col,value):
R,C=self.im.dim()
self.im[row*C+col]=value
# get image pixel value
def Get(self,row,col):
R,C=self.im.dim()
return self.im[row*C+col]
return ScorpionImage(rows,cols)
Example 2: Manipulate a Scorpion Image using ScorpionImage instance
image = CreateScorpionImage(0,0)
image.GetImageMatr('Image') # on RGB images use Image.I to retrieve intensity plane
for i0 in range(40):
p = image.Get(i0*10,i0*10)
p += 100
if p>255: p=255
image.Set(i0*10,i0*10,p)
image.SetImageMatr('Image')
|