Skip to content

Instantly share code, notes, and snippets.

@tune
Created November 5, 2012 01:53
Show Gist options
  • Save tune/4014839 to your computer and use it in GitHub Desktop.
Save tune/4014839 to your computer and use it in GitHub Desktop.
コマンドラインで画像のPSNRを測定する ref: http://qiita.com/items/ca9ffa66bd1703c745dd
compare -metric PSNR ref.jpg target.jpg diffpng
#!/bin/env ruby
# -*- coding: utf-8 -*-
#
# Usage
# $ ruby comp.rb TARGET_FOLDER
#
require 'rubygems'
require 'systemu'
# http://www.imagemagick.org/script/command-line-options.php#metric
COMPARE_METRIC = "PSNR"
REF_FOLDER = "RefFolder"
REF_FORMAT_EXT = ".bmp"
TARGET_FOLDER = ARGV[0]
Dir.glob(File.join(TARGET_FOLDER, "*")).sort.each do |target_file|
ref_file = File.join(REF_FOLDER, File.basename(target_file, ".jpg")) + REF_FORMAT_EXT
command = "compare -metric #{COMPARE_METRIC} #{ref_file} #{target_file} diff.png"
# Metrics value is outputed to stderr somehow
status, stdout, stderr = systemu command
puts "#{target_file}\t#{stderr}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment