Kumita← Open visual lesson

Search the picture

The code behind the picture

Follow the lesson’s implementation, one code cell at a time.

Choose a language and read the cells in order. These are small teaching examples; the visual lesson runs separately.

Follow the calculation

Same inputs · Same operation · Same result

3 teaching cells · Python standard library · Read-only

  1. 1. Prepare the inputs

    Use these small, explicit inputs to follow the calculation.

    import json
    
    image = [[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]]
  2. 2. Visit candidate windows

    Slide a 2 × 2 window with stride 2. We report each crop mean to make the traversal visible; the visual lesson instead feeds crops to its saved trained classifier.

    result = []
    for row in range(0, 3, 2):
        for column in range(0, 3, 2):
            crop = [image[row+dy][column+dx] for dy in range(2) for dx in range(2)]
            result.append({"row": row, "column": column, "mean": sum(crop)/4})
  3. 3. Inspect the result

    Print the result as JSON so both languages use the same output format.

    print(json.dumps(result))

Expected result

Running the three cells in order produces this result in either language.

[
  {
    "row": 0,
    "column": 0,
    "mean": 3.5
  },
  {
    "row": 0,
    "column": 2,
    "mean": 5.5
  },
  {
    "row": 2,
    "column": 0,
    "mean": 11.5
  },
  {
    "row": 2,
    "column": 2,
    "mean": 13.5
  }
]