First time here? Check out the FAQ!

Ask Your Question
0

How to fix problem when creating image histogram

asked 5 years ago

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
Preview: (hide)

Comments

1

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

tmonteil gravatar imagetmonteil ( 5 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 5 years ago

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?

Preview: (hide)
link

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

Stats

Asked: 5 years ago

Seen: 217 times

Last updated: Nov 24 '19