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

42
LINES

< > BotCompany Repo | #487 - Image distinguisher by randomly selected color [learner part]

Lua code - Image distinction (learner)

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:
--   nil if still learning
--   {"#executorid", varname1=value1, varname2=value2, ...}

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

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 nil
    end
    selectColor(lastimg1)
    class2sampled = solution
    print("color of class "..(class2sampled and "2" or "1")..": ".. num2hex(color))
  end
  
  lastimg1, lastimg2 = img1, img2
  
  flag1 = containsColor(img1, color)
  flag2 = containsColor(img2, color)
  if flag1 == flag2 then
    color = nil
    return nil
  end
  guess = flag1 == class2sampled
  return {"#486", class2sampled=class2sampled, color=color}
end

Author comment

Began life as a copy of #484

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: #487
Snippet name: Image distinguisher by randomly selected color [learner part]
Eternal ID of this version: #487/1
Text MD5: a76912bdb80b158dcacf700446cee68f
Author: stefan
Category:
Type: Lua code - Image distinction (learner)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-03 18:26:57
Source code size: 1209 bytes / 42 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 381 / 93
Referenced in: [show references]

Formerly at http://tinybrain.de/487 & http://487.tinybrain.de