Skip to content

Instantly share code, notes, and snippets.

@shoesCodeFor
Forked from jeffkreeftmeijer/1.png
Created August 29, 2018 20:23
Show Gist options
  • Select an option

  • Save shoesCodeFor/210e9f13cc07b9e6133e324f667263db to your computer and use it in GitHub Desktop.

Select an option

Save shoesCodeFor/210e9f13cc07b9e6133e324f667263db to your computer and use it in GitHub Desktop.

Revisions

  1. Jeff Kreeftmeijer revised this gist Apr 25, 2011. No changes.
  2. Jeff Kreeftmeijer revised this gist Apr 18, 2011. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions delta_e_diff.rb
    Original file line number Diff line number Diff line change
    @@ -14,17 +14,20 @@
    images.first.height.times do |y|
    images.first.row(y).each_with_index do |pixel, x|
    unless pixel == images.last[x,y]
    diff << [x,y]

    score = Math.sqrt(
    (r(images.last[x,y]) - r(pixel)) ** 2 +
    (g(images.last[x,y]) - g(pixel)) ** 2 +
    (b(images.last[x,y]) - b(pixel)) ** 2
    )
    ) / Math.sqrt(MAX ** 2 * 3)

    output[x,y] = grayscale(MAX - ((score / Math.sqrt(MAX ** 2 * 3)) * 255).round)
    output[x,y] = grayscale(MAX - (score * 255).round)
    diff << score
    end
    end
    end

    puts "pixels (total): #{images.first.pixels.length}"
    puts "pixels changed: #{diff.length}"
    puts "image changed (%): #{(diff.inject {|sum, value| sum + value} / images.first.pixels.length) * 100}%"

    output.save('diff.png')
  3. Jeff Kreeftmeijer revised this gist Apr 18, 2011. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion delta_e_diff.rb
    Original file line number Diff line number Diff line change
    @@ -28,4 +28,3 @@
    end

    output.save('diff.png')

  4. Jeff Kreeftmeijer created this gist Apr 18, 2011.
    Binary file added 1.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added 2.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    31 changes: 31 additions & 0 deletions delta_e_diff.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    require 'chunky_png'
    include ChunkyPNG::Color


    images = [
    ChunkyPNG::Image.from_file('1.png'),
    ChunkyPNG::Image.from_file('2.png')
    ]

    output = ChunkyPNG::Image.new(images.first.width, images.last.width, WHITE)

    diff = []

    images.first.height.times do |y|
    images.first.row(y).each_with_index do |pixel, x|
    unless pixel == images.last[x,y]
    diff << [x,y]

    score = Math.sqrt(
    (r(images.last[x,y]) - r(pixel)) ** 2 +
    (g(images.last[x,y]) - g(pixel)) ** 2 +
    (b(images.last[x,y]) - b(pixel)) ** 2
    )

    output[x,y] = grayscale(MAX - ((score / Math.sqrt(MAX ** 2 * 3)) * 255).round)
    end
    end
    end

    output.save('diff.png')

    Binary file added diff.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  5. Jeff Kreeftmeijer created this gist Apr 18, 2011.
    30 changes: 30 additions & 0 deletions delta_e_diff.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    require 'chunky_png'
    include ChunkyPNG::Color


    images = [
    ChunkyPNG::Image.from_file('1.png'),
    ChunkyPNG::Image.from_file('2.png')
    ]

    output = ChunkyPNG::Image.new(images.first.width, images.last.width, WHITE)

    diff = []

    images.first.height.times do |y|
    images.first.row(y).each_with_index do |pixel, x|
    unless pixel == images.last[x,y]
    diff << [x,y]

    score = Math.sqrt(
    (r(images.last[x,y]) - r(pixel)) ** 2 +
    (g(images.last[x,y]) - g(pixel)) ** 2 +
    (b(images.last[x,y]) - b(pixel)) ** 2
    )

    output[x,y] = grayscale(MAX - ((score / Math.sqrt(MAX ** 2 * 3)) * 255).round)
    end
    end
    end

    output.save('diff.png')