Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

26
LINES

< > BotCompany Repo | #380 // hashImage (include)

Lua code

get("#356") -- num2hex
get("#348") -- rgb functions

function hashImage(img)
  local hash = 0
  local w, h = img.width, img.height
  
  for y = 0, h-1 do
    for x = 0, w-1 do
      local pix = img.getInt(x, y)
      local r, g, b = rgb(pix)
      local p = r+g*33+b*71
      local scale = bit32.band(y*w+x, 0xFFFF)+1
      --hash = (hash * a + pix) % 0x100000000
      --a = (a * b) % 0x100000000
      local arg = (p+1)*scale
      hash = bit32.bxor(hash, arg)
      --[[if x < 10 then
        print("scale", scale, "pix", pix, "p", p, "arg", arg, "hash", hash)
      end]]
    end
    --print("y", y, "hash", hash)
  end
  
  return num2hex(hash, 8)
end

Author comment

Probably fairly crappy (might cause hash collisions), but I guess it can be used for now

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #380
Snippet name: hashImage (include)
Eternal ID of this version: #380/1
Text MD5: 0137480d9879d478d1cbaea509066e51
Author: stefan
Category: hash functions
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-17 20:35:12
Source code size: 681 bytes / 26 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 841 / 252
Referenced in: #381 - Image Hasher (Stefan's variant)
#386 - Magic Wand + Hashes
#397 - OS identifier (by start button)
#402 - Magic Wand + Hashes (optimized III)
#403 - Magic Wand + Hashes (one column)
#404 - Magic Wand + Hashes (column range, improving)
#405 - Magic Wand + Hashes for Internet menu
#406 - Magic Wand + Hashes (special case recognizer)
#411 - Grid + Floodfill with hashes
#415 - Rough-Hash Function
#420 - Grid + Floodfill with hashes / limited start area (for start menus)
#421 - Grid + Floodfill with hashes / limited start area (for start menus), optimized
#422 - Grid + Floodfill with hashes (with virtual stack)
#423 - Grid + Floodfill with hashes (hacked for galculator)
#425 - LXTerminal Contents Segmenter
#426 - LXTerminal Contents Recognizer
#427 - LXTerminal character reference maker
#429 - LXTerminal character reference maker 2
#442 - Grid + Floodfill with hashes (size 3)
#444 - White Grid + Floodfill
#445 - White Grid
#453 - Java character reference maker
#456 - Java character reference maker (non-bold)
#461 - Grid + Floodfill with hashes (size 2)
#463 - Grid + Floodfill (size = 50)
#464 - Grid + Floodfill (size = 15)
#465 - Grid + Floodfill (size = 10)
#467 - Movement detector
#468 - Movement detector (monte carlo)
#469 - Grid + Floodfill with hashes (for lighter elements)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)