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


< > BotCompany Repo | #484 - Image distinguisher by randomly selected color

Lua code

get("#356") -- num2hex
get("#485") -- containsColor

-- Job: Distinguish two classes of images
-- Two images are supplied at once, one of each class.
-- Task is to find out if the two images are swapped or not.
-- input variables: img1, img2, solution [to last pair]
-- output: a function returning true or false (swapped or no)

function selectColor(img)
  local x, y = math.random(0, img.width-1), math.random(0, img.height-1)
  color = img.getInt(x, y)

return function()
  -- select a new color when last guess was wrong
  if solution ~= guess then color = nil end
  if color == nil then
    if solution == nil then
      lastimg1, lastimg2 = img1, img2
      return false -- just return something
    class2sampled = solution
    print("color of class "..(class2sampled and "2" or "1")..": ".. num2hex(color))
  lastimg1, lastimg2 = img1, img2
  flag1 = containsColor(img1, color)
  flag2 = containsColor(img2, color)
  if flag1 == flag2 then
    color = nil
    return false
  guess = flag1 == class2sampled
  return guess

Author comment

Began life as a copy of #483

test run  test run with input  download  show line numbers   

Travelled to 8 computer(s): aoiabmzegqzx, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #484
Snippet name: Image distinguisher by randomly selected color
Eternal ID of this version: #484/1
Text MD5: 570216e2e5c9b9c845e8e558916f517e
Author: stefan
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-04 22:40:53
Source code size: 1133 bytes / 40 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 431 / 179
Referenced in: [show references]

Formerly at &