[Tutor] [tutor] Finding image statistics
varsha.purohit at gmail.com
Mon Mar 3 18:46:48 CET 2008
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.... 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....
On Sun, Mar 2, 2008 at 4:45 PM, Kent Johnson <kent37 at tds.net> wrote:
> Varsha Purohit wrote:
> > I am getting this list as an output
> > [268541.0, 264014.0, 324155.0]
> This is the sum of the values of the red pixels, etc. They are not
> counts, but sums. So if you have an image with the two pixels
> (1, 2, 3), (4, 5, 6) you would get a sum of (5, 7, 9).
> > Actually in my code i am finding difference between two images and i
> > need to count the number of pixels which appear as a difference of these
> > two images. These values i m getting as output are little large.
> So you want a count of the number of pixels that differ between the two
> images? Maybe this:
> diff = ImageChops.difference(file1, file2)
> # Convert to grayscale so differences are counted just once per pixel
> diff = ImageOps.grayscale(diff)
> # Convert each difference to 0 or 1 so we can count them
> # Clipping function
> def clip(x):
> return 1 if x >= 1 else 0
> # Apply the clipping function
> diff = Image.eval(diff, clip)
> print ImageStat.Stat(diff).sum
> > i m pasting my code again....
> > file1=Image.open("./pics/original.jpg")
> > file2=Image.open(val)
> > diff = ImageChops.subtract(file1,file2,0.3)
> > stat1 = ImageStat.Stat(diff)
> > count1=stat1.sum
> > print count1
> > diff.save("./pics/diff"+".jpg")
> > diff.show()
> > AS you can see i am finding difference of two images which are nearly
> > identical. But they have some pixels that are different and i can see
> > that in the output image diff.jpg. So i am trying to put this difference
> > image in the imagestat and trying to see if i can get to count the
> > number of pixels .......
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor