Skip to content

Instantly share code, notes, and snippets.

@shio-phys
Created March 1, 2016 08:36
Show Gist options
  • Save shio-phys/d31a42266e32d23754e3 to your computer and use it in GitHub Desktop.
Save shio-phys/d31a42266e32d23754e3 to your computer and use it in GitHub Desktop.
#ガンマ補正
def self.lut(i, gamma)
(i.to_f/255.0) ** (1.0/gamma) * 255.0
end
#ガンマ補正された画像を生成
def self.gamma_correction_img(img, gamma = GAMMA_DEFAULT)
gamma_correction_img = CvMat.new(img.rows, img.cols, CV_8U, 1)
(0...img.rows).each do |y|
(0...img.cols).each do |x|
gamma_correction_img[y, x] = CvScalar.new(lut(img[y, x][0].to_f, gamma), lut(img[y, x][1].to_f, gamma), lut(img[y, x][2].to_f, gamma))
end
end
gamma_correction_img
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment