ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 24 Nov 2019 20:25:33 +0100How to fix problem when creating image histogramhttps://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/ 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
Thu, 21 Nov 2019 13:02:42 +0100https://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/Comment by tmonteil for <p>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?</p>
<p>Below is my code </p>
<pre><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
</code></pre>
https://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/?comment=48840#post-id-48840Could you please provide the whole code. In particular, how is `im` defined ?Thu, 21 Nov 2019 16:23:29 +0100https://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/?comment=48840#post-id-48840Answer by Sébastien for <p>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?</p>
<p>Below is my code </p>
<pre><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
</code></pre>
https://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/?answer=48865#post-id-48865Chances 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?Sun, 24 Nov 2019 20:25:33 +0100https://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/?answer=48865#post-id-48865