Skip to content

Instantly share code, notes, and snippets.

@bartolsthoorn
Created January 31, 2011 11:16
Show Gist options
  • Save bartolsthoorn/803914 to your computer and use it in GitHub Desktop.
Save bartolsthoorn/803914 to your computer and use it in GitHub Desktop.
def histogram(location)
if !@texplayinit
init_texplay
end
histogram_image = TexPlay.create_blank_image(@@Win, 101, 1022)
img = Gosu::Image.new(@@Win, @imagefilename)
@histopixels = Array.new
101.times{ |x|
@histopixels[x] = 0
}
img.each{ |pixel|
pixel = grayscale(pixel)
intensity = (pixel[0].round(2))*100
@histopixels[intensity] = @histopixels[intensity] + 1
}
@xcount = 0
@histopixels.each{ |p|
p.times{ |y|
histogram_image.pixel @xcount, y, :color => [1, 0, 1, 1]
}
@xcount = @xcount + 1
}
histogram_image.save location
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment