Ask Your Question

How to fix problem when creating image histogram

asked 2019-11-21 13:02:42 +0200

isida gravatar image

Hello, I'm trying to develop a function that calculates histograms for the colored images. When I run my program it says 'too many values to unpack (expected 2)'. What am I doing wrong here?

Below is my code

Collor_Channel =("r" , "g", "b")
PixelNum, Collor_Channel = im.shape
ImageHistogram = np.zeros(256)
    for i in range(PixelNum[0]):
          for j in range(PixelNum[1]):
               for x in range(PixelNum[2]):
                     totalvalue = im [j,i,x]
                            ImageHistogram[int(totalvalue)] += 1

                     return ImageHistogram
edit retag flag offensive close merge delete



Could you please provide the whole code. In particular, how is im defined ?

tmonteil gravatar imagetmonteil ( 2019-11-21 16:23:29 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-11-24 20:25:33 +0200

Sébastien gravatar image

Chances are that the problem in the line PixelNum, Collor_Channel = im.shape:

sage: shape = (1,2,3)
sage: PixelNum, Collor_Channel = shape
Traceback (most recent call last):

----> 1 PixelNum, Collor_Channel = shape

ValueError: too many values to unpack

Did you check the value of im.shape in particular if its size is really equal to 2?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-11-21 13:02:42 +0200

Seen: 51 times

Last updated: Nov 24 '19