Created
November 5, 2012 01:53
-
-
Save tune/4014839 to your computer and use it in GitHub Desktop.
コマンドラインで画像のPSNRを測定する ref: http://qiita.com/items/ca9ffa66bd1703c745dd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compare -metric PSNR ref.jpg target.jpg diffpng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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