0
A
回答
0
有幾種方法可以做到這一點。
1)最好的辦法是使用Rmagick簽名我看來(感謝this useful manual):
require 'RMagick'
new_image = Magick::Image.read(new_photo)[0] ## new_photo = "/your/dir/file.jpg"
expected_image = Magick::Image.read(expected_photo)[0]
new_image.signature.should eql expected_image.signature
或
diff_img, diff_metric = img1[0].compare_channel(img2[0], Magick::MeanSquaredErrorMetric)
2)您也可以使用raster_graphics庫(rosettacode.org):
require 'raster_graphics'
class RGBColour
# the difference between two colours
def -(a_colour)
(@red - a_colour.red).abs +
(@green - a_colour.green).abs +
(@blue - a_colour.blue).abs
end
end
class Pixmap
# the difference between two images
def -(a_pixmap)
if @width != a_pixmap.width or @height != a_pixmap.height
raise ArgumentError, "can't compare images with different sizes"
end
sum = 0
each_pixel {|x,y| sum += self[x,y] - a_pixmap[x,y]}
Float(sum)/(@width * @height * 255 * 3)
end
end
lenna50 = Pixmap.open_from_jpeg('Lenna50.jpg')
lenna100 = Pixmap.open_from_jpeg('Lenna100.jpg')
puts "difference: %.5f%%" % (100.0 * (lenna50 - lenna100))
#=>:
#difference: 1.62559%
相關問題
- 1. Java比較兩張圖
- 2. 比較兩張圖片
- 3. 如何比較兩張圖片中的兩條曲線?
- 4. 比較兩張圖的結構
- 5. 如何比較兩個圖像uisng vb.net?
- 6. 兩幅圖像的圖像比較
- 7. 用matlab比較兩張圖片
- 8. 使用PHP比較兩張圖片
- 9. 比較兩張臉opencv
- 10. 錯誤,在比較兩張
- 11. 比較兩幅圖像
- 12. OSX:比較兩個圖像
- 13. 比較兩個圖像android
- 14. 使用C#比較2張圖像
- 15. 比較撲克牌中的兩張牌
- 16. 比較android中的兩張臉
- 17. Lua中兩張桌子的比較?
- 18. 比較PHP中的兩幅圖像
- 19. 比較Android中的兩個圖像
- 20. 比較IOS中的兩個圖像8
- 21. 通過直方圖比較兩個圖像並在一張圖中繪圖
- 22. 使用RGB值比較兩張圖像。 (Java)
- 23. 如何用iphone sdk比較兩張圖片?
- 24. 如何比較兩張圖像來檢測重複項和裁剪重複項?
- 25. 在兩張紙中比較整行
- 26. 在JavaScript中比較兩個圖像
- 27. 我如何比較圖像
- 28. GPUImage:如何混合兩張不同大小的圖像,同時保持兩張圖像的原始高寬比?
- 29. 如何比較圖像(緩存圖像)?
- 30. 如何比較Xcode中的兩個圖像?