user297850
user297850

Reputation: 8005

regarding understanding a code segment on multi-dimensional array

I am trying to understanding a program, which includes the following code segment

In the code segment, hypes is just a parameter setting extracted from a json file.

As shown in the code segment, background_color = np.array(hypes['data']['background_color']), I printed hypes['data']['background_color'] it out, which is [0] ; therefore background_color is of shape (1,). I am confused about gt_bool = (gt_image != background_color). How does it work? It seems to me that gt_image should be an array of the image size shape, e.g.,(640,480) but background_color is of shape (1,), I do not understand how does gt_image != background_color work?

def _load_gt_file(hypes, data_file=None):
"""Take the data_file and hypes and create a generator. The generator outputs the image and the gt_image."""
    base_path = os.path.realpath(os.path.dirname(data_file))
    files = [line.rstrip() for line in open(data_file)]
    for epoche in itertools.count():
        shuffle(files)
        for file in files:
            image_file, gt_image_file = file.split(" ")
            image_file = os.path.join(base_path, image_file)
            gt_image_file = os.path.join(base_path, gt_image_file)

            image = scipy.misc.imread(image_file)
            gt_image = scp.misc.imread(gt_image_file, flatten=True)

      yield image, gt_image


def _make_data_gen(hypes, phase, data_dir):
"""Return a data generator that outputs image samples."""

  background_color = np.array(hypes['data']['background_color'])
  data = _load_gt_file(hypes, data_file)
  for image, gt_image in data:
       gt_bool = (gt_image != background_color)

Upvotes: 0

Views: 45

Answers (1)

kadnarim
kadnarim

Reputation: 177

gt_bool will be a boolean array of the same shape as gt_image, set to True for elements that are equal to background_color and False for elements that are not.

Upvotes: 1

Related Questions