code: def countless_if(array):
      factor = (2, 2, 1)
      shape = array.shape
  
      if len(shape) < 3:
          array = array[:, :, np.newaxis]
          shape = array.shape
  
      output_shape = tuple(
          int(math.ceil(s / f)) for s, f in zip(shape, factor)
      )
      output = np.zeros(output_shape, dtype=array.dtype)
  
      for chan in range(0, shape[2]):
          for x in range(0, shape[0], 2):
              for y in range(0, shape[1], 2):
                  block = array[x : x + 2, y : y + 2, chan]  # 2x2 block
  
                  if block[0, 0] == block[1, 0]:
                      pick = block[0, 0]
                  elif block[0, 0] == block[0, 1]:
                      pick = block[0, 0]
                  elif block[1, 0] == block[0, 1]:
                      pick = block[1, 0]
                  else:
                      pick = block[1, 1]
  
                  output[x // 2, y // 2, chan] = pick
  
      return np.squeeze(output)
  
imports: from __future__ import print_function, division
  import six
  from six.moves import range
  from collections import defaultdict
  from functools import reduce
  import operator
  import io
  import os
  from PIL import Image
  import math
  import numpy
  import random
  import sys
  import time
  from tqdm import tqdm
  from scipy import ndimage
label_desc: Use image node_id 14 for calling a global function with example usage: countless_if(array) and returns: np