Rmagick直方图问题
我在访问 color_histogram() 返回的哈希时遇到问题。我的图像中只有黑白像素,这非常令人沮丧。
当我
puts hist.inspect() # returns "{red=0, green=0, blue=0, opacity=0=>779753, red=65535, green=65535, blue=65535, opacity=0=>6679}"
根据文档进行操作时,关键是 Pixel 对象,因此我构造了
black = Magick::Pixel.from_color('black')
white = Magick::Pixel.from_color('white')
puts black.inspect # red=0, green=0, blue=0, opacity=0
puts white.inspect # red=65535, green=65535, blue=65535, opacity=0
puts hist[white] # raises exception: `[]': can't convert Magick::Pixel into Integer (TypeError)
如何轻松访问直方图的任何想法?
谢谢
I'm having problems accessing the hash returned by color_histogram(). There are only black and white pixels in my image, and this is very frustrating.
When I do
puts hist.inspect() # returns "{red=0, green=0, blue=0, opacity=0=>779753, red=65535, green=65535, blue=65535, opacity=0=>6679}"
According to the documentation, the key is a Pixel object, so I construct
black = Magick::Pixel.from_color('black')
white = Magick::Pixel.from_color('white')
puts black.inspect # red=0, green=0, blue=0, opacity=0
puts white.inspect # red=65535, green=65535, blue=65535, opacity=0
puts hist[white] # raises exception: `[]': can't convert Magick::Pixel into Integer (TypeError)
Any ideas how I can access the histogram easily?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在
color_histogram 之间的某个位置更改
调用和您的hist
hist[white]
。这对我来说适用于一个简单的黑白bw.png
:并且您可以使用数组轻松重现“无法将 Magick::Pixel 转换为整数(TypeError)”错误:
哈希永远不会通过简单的访问产生 TypeError。
You're changing
hist
somewhere between yourcolor_histogram
call and yourhist[white]
. This works for me with a simple black and whitebw.png
:And you "can't convert Magick::Pixel into Integer (TypeError)" error is easily reproduced using an Array:
A Hash will never produce that TypeError from a simple access.