RMagick 1.9.3: examples/histogram.rb - erro

C

ces.fci.junk

Trying to run the histogram.rb ~/$myimage produces the following error:

Creating b194000514_7064_Histogram.miffhistogram.rb:180:in `histogram':
undefined method `+' for nil:NilClass (NoMethodError)
from histogram.rb:179:in `each'
from histogram.rb:179:in `histogram'
from histogram.rb:177:in `times'
from histogram.rb:177:in `histogram'
from histogram.rb:280

For the moment commenting these lines will let it run and output a
viewable miff (beginning at line 180):
#red[pixel.red] += 1
#green[pixel.green] += 1
#blue[pixel.blue] += 1

# Only count opacity channel if some pixels are not
opaque.
if !opaque?
alpha[pixel.opacity] += 1
end
v = pixel_intensity(pixel)
#int[v] += 1


Potentially relevent (or not relevent) information:
Ruby 1.8.2
ImageMagick 6.1.9
Linux 2.6.10

The other examples appear to run without issue.
I am also relatively new to Ruby if that matters.

I tried adding these in the appropiate locations (figured it may have
had problems adding to nil):
red[pixel.red] = 0 if red[pixel.red].nil?
blue[pixel.blue] = 0 if blue[pixel.blue].nil?
green[pixel.green] = 0 if green[pixel.green].nil?
#...
alpha[pixel.opacity] = 0 if alpha[pixel.opacity].nil?
#...
int[v] = 0 if int[v].nil?

The result is another error, but I am not sure how to get around it:
Creating b194000514_7064_Histogram.miff.histogram.rb:5:in `max':
undefined method `<=>' for nil:NilClass (NoMethodError)
from histogram.rb:208:in `each'
from histogram.rb:208:in `max'
from histogram.rb:208:in `histogram'
from histogram.rb:292

any thoughts on the matter?

Clayton
 
R

rmagick

Trying to run the histogram.rb ~/$myimage produces the following error:

Creating b194000514_7064_Histogram.miffhistogram.rb:180:in `histogram':
undefined method `+' for nil:NilClass (NoMethodError)
from histogram.rb:179:in `each'
from histogram.rb:179:in `histogram'
from histogram.rb:177:in `times'
from histogram.rb:177:in `histogram'
from histogram.rb:280

Hmmm...I get it, too. I should I say I "got" it, because after I
started investigating the problem I started getting other very odd
errors and then it started working. Now I can't make it happen anymore.
These are classic symptoms of a wild pointer either in RMagick or
ImageMagick. I'll poke around a little bit more. Whatever the problem
is, it can't be fixed by changing the script.

Thanks for pointing this out.
 
C

ces.fci.junk

I believe I figured it out although I'm not entirely sure of the
solution (unless you can tell me how to loop through all the values and
unset the nil values -- note: i'm still new to ruby).
running this lets me know there is a lot of nil values which would
explain the "nil:NilClass (NoMethodError)" -- nil doesn't have the max
method:
for i in red
p "nil!" if i.nil?
end

Now, what is strange about this is that the arrays are *already*
defined to all have zero:
red = Array.new(HISTOGRAM_COLS, 0)
green = Array.new(HISTOGRAM_COLS, 0)
blue = Array.new(HISTOGRAM_COLS, 0)
alpha = Array.new(HISTOGRAM_COLS, 0)
int = Array.new(HISTOGRAM_COLS, 0)

I tried changing all of the 0's to 1's to see if that would make a
difference (it did not). I also tried using the fill method which had
no effect.

but, if you say it is a wild pointer I'll concede.

I had to download xwindow.c and xwindow.h from the sourceforge page
since they weren't included with my source[for ImageMagick] -- I had
received a compile error which said they were missing (maybe that is
related[?]).

Clayton
 
T

Timothy Hunter

Now, what is strange about this is that the arrays are *already*
defined to all have zero:

I'm reasonably sure there's nothing wrong with the script itself, at
least sure enought that it's not at the top of my list for possible
causes. I'll investigate.
 
T

Timothy Hunter

I believe I figured it out although I'm not entirely sure of the
solution (unless you can tell me how to loop through all the values and
unset the nil values -- note: i'm still new to ruby).
running this lets me know there is a lot of nil values which would
explain the "nil:NilClass (NoMethodError)" -- nil doesn't have the max
method:
for i in red
p "nil!" if i.nil?
end

Would you mind issuing this little command and sending me the output?

ruby -r rmagick -e'p Magick::Long_version'

Thanks!
 
C

ces.fci.junk

Here's the output:
% ruby -r RMagick -e'puts Magick::Long_version'
This is RMagick 1.9.3 ($Date: 2005/10/13 23:01:29 $) Copyright (C) 2005
by Timothy P. Hunter
Built with ImageMagick 6.1.9 01/20/05 Q16 http://www.imagemagick.org
Built for ruby 1.8.2 (2004-12-25) [i686-linux]
Web page: http://rmagick.rubyforge.org
Email: (e-mail address removed)

Clayton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top