# [Tutor] [tutor] Finding image statistics

Varsha Purohit varsha.purohit at gmail.com
Mon Mar 10 01:53:37 CET 2008

```Hello All,
I had posted this question in this community. I have a trouble.
Actually in my application i need to multiply the resultant value i am
getting with a cellsize. I am getting this cellsize by reading an ascii
file's header. But when i am trying to multiply it with the result of
imagestat i am getting an error.

this is my code.

def ImageStatistics(file1,file2,inFile):

# find the pixels that are different in two images
diff = ImageChops.difference(file1,file2)
#shows the resultant image
diff.show()
#convert the different pixels into grayscale so that they are counted
once for each pixel
diff = ImageOps.grayscale(diff)

temp= hdr[4].strip().split() # temp is a list which is ['cellsize',
'127']
cellsize = temp[1]

def clip(x):
if x>=1:
return 1
else:
return 0
# apply the clipping function to eval
diff = Image.eval(diff,clip)

#return the resultant area
val = ImageStat.Stat(diff).sum
area = val * cellsize
print "area is ",area
return area

i am getting an error that i cannot combine imagestat with cellsize and i
cannot multiply it like that. But in my application i need to multiply
cellsize with the value i am getting in the image.eval....

i tried to multiply cellsize with 1 in the clip function where i am writing
return 1*cellsize.

but even it is not working .... can anyone tell me what i am doing wrong
here ???
On Mon, Mar 3, 2008 at 12:55 PM, Kent Johnson <kent37 at tds.net> wrote:

> Varsha Purohit wrote:
> > Yeahh so by doing this i am counting only the difference part since we
> > have grayscaled the image and assuming it will count only the pixels
> > that evolve as difference....
>
> Yes
>
> > if i use sum2 instead of sum i think  it
> > will give squared sum which is area... and if i just use count it would
> > count the number of pixels developed like that... sounds interesting ..
> > thanks for throwing light for me in right direction....
>
> No. First, pixels are already a measure of area. Second, if each pixel
> value is 0 or 1, squaring the values won't make any difference.
>
> Kent
>

--
Varsha Purohit,