Gimp-Forum.net
How it is possible that Gimp while exporting histogram counts more pixels than there - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions)
+--- Thread: How it is possible that Gimp while exporting histogram counts more pixels than there (/Thread-How-it-is-possible-that-Gimp-while-exporting-histogram-counts-more-pixels-than-there)



How it is possible that Gimp while exporting histogram counts more pixels than there - niitard - 06-12-2020

Hello,

I'm currently learning programming in python, one of subject that i'm trying to cover now is working with image.  So i wanted to created o program that's counting how many pixel of each colour is in my image (which is 10x10 pixel gray scale). So i created the image all black with 24 white pixel and my program, all works well. It counts 24 pixel of "255" and 76 of "0.

But here comes the problem:

when i have used the Gimp [color] -> [information] -> [export histogram] to file i got the results like this

Range start,Value

0 , 76.0

1 , 0.0

2 , 0.0
[...]

253 , 0.0

254 , 24.0

255 , 24.0


it looks like, the Gimp software counted white pixel two times, so when they are summed up that makes 24 + 24 + 76 = 124 , and yet the picture size is still 10x10  = 100

i've searched the internet but cant find the clue:
How it is possible that Gimp while exporting histogram counts more pixels than there are really in the picture?

Thank you for help Smile


RE: How it is possible that Gimp while exporting histogram counts more pixels than there - Ofnuts - 06-12-2020

Yes, likely a bug, nice finding.

Didn't see you code, but if you access each pixel in turn using get_pixel(), you code will not scale to real-life images. In Python your can use "pixel regions", which is a nbig array-like structure that you can access in Python (it even supports slices).


RE: How it is possible that Gimp while exporting histogram counts more pixels than there - niitard - 06-12-2020

(06-12-2020, 03:40 PM)Ofnuts Wrote: Yes, likely a bug, nice finding.

Didn't see you code, but if you access each pixel in turn using get_pixel(), you code will not scale to real-life images. In Python your can use "pixel regions", which is a nbig array-like structure that you can access in Python (it even supports slices).

from PIL import Image
import numpy as np

img = Image.open('start.bmp')

arr=np.array(img)
print (arr)

#im still learning arrays so i changed it to list that im more familiar with

b=arr.tolist()

print ()

flat_list=[]

for sublist in b:
    for item in sublist:
        flat_list.append(item)




white_dots=0
black_dots=0

for i in flat_list:
    if i == 255:
        white_dots+=1
    if i == 0:
        black_dots+=1

print ('number 255: ', white_dots)
print ('number 0: ', black_dots)


thats my code Smile
thank you very much Big Grin


RE: How it is possible that Gimp while exporting histogram counts more pixels than there - Ofnuts - 06-12-2020

Oh, I thought you where doing a Python Gimp script...

You may be more familiar with lists, but the numpy array is much faster. Not as bad as a Gimp get_pixel() but for real-size images numpy will make a very significant difference.


RE: How it is possible that Gimp while exporting histogram counts more pixels than there - niitard - 06-12-2020

(06-12-2020, 04:16 PM)Ofnuts Wrote: Oh, I thought you where doing a Python Gimp script...

You may be more familiar with lists, but the numpy array is much faster. Not as bad as a Gimp get_pixel() but for real-size images numpy will make a very significant difference.

Thank you Smile