Пример #1
0
def process_img(img, key):
    if 'distance' in key or 'depth' in key or 'seg' in key:
        img = img.astype(np.float)
        if not "seg" in key:
            min_val = np.min(img)
            img -= min_val
        max_val = np.max(img)
        if "seg" in key:
            max_val = 36.0
            print(
                "Assuming, there are 36 total classes (NYU), if there are more this will cause a bug!"
            )
        if max_val != np.inf:
            img /= max_val
        else:
            img /= np.max(img)
        # clipping to avoid image errors
        img = np.clip(img, 0.0, 1.0)
        if len(img.shape) == 3:
            img = img[:, :, 0]
    elif 'flow' in key:
        try:
            # This import here is ugly, but else everytime someone uses this script it demands opencv and the progressbar
            sys.path.append(os.path.join(os.path.dirname(__file__)))
            from utils import flow_to_rgb
        except ImportError:
            raise ImportError(
                "Using .hdf5 containers, which contain flow images needs opencv-python and progressbar "
                "to be installed!")

        img = flow_to_rgb(img)
    elif "normals" in key:
        img = np.clip(img, 0.0, 1.0)
    return img
Пример #2
0
def process_img(img, key):
    if 'distance' in key or 'depth' in key or 'seg' in key:
        img = img.astype(np.float)
        if not "seg" in key:
            min_val = np.min(img)
            img -= min_val
        max_val = np.max(img)
        if "seg" in key:
            max_val = 36.0
            print(
                "Assuming, there are 36 total classes (NYU), if there are more this will cause a bug!"
            )
        if max_val != np.inf:
            img /= max_val
        else:
            img /= np.max(img)
        # clipping to avoid image errors
        img = np.clip(img, 0.0, 1.0)
        if len(img.shape) == 3:
            img = img[:, :, 0]
    elif 'flow' in key:
        img = flow_to_rgb(img)
    elif "normals" in key:
        img = np.clip(img, 0.0, 1.0)
    return img
Пример #3
0
def visFile(filePath, show=True):
    if os.path.exists(filePath):
        if os.path.isfile(filePath):
            with h5py.File(filePath, 'r') as data:
                if args.key is not None and args.key in [
                        key for key in data.keys()
                ]:
                    keys = [key for key in data.keys() if key == args.key]
                else:
                    keys = [key for key in data.keys()]
                for key in keys:
                    val = np.array(data[key])
                    if 'flow' in key and 'version' not in key:
                        val = flow_to_rgb(val)

                    if len(val.shape) == 2 or len(
                            val.shape) == 3 and val.shape[2] == 3:
                        plt.figure()
                        plt.title("{} in {}".format(
                            key, os.path.basename(filePath)))
                        val = process_img(val, key)
                        if len(val.shape) == 2 or len(
                                val.shape) == 3 and val.shape[2] == 1:
                            plt.imshow(val, cmap='jet')
                        else:
                            plt.imshow(val)
                if show:
                    plt.show()
        else:
            print("The path is not a file")
    else:
        print("The file does not exist: {}".format(args.hdf5))
Пример #4
0
    def vis_data(key, data, full_hdf5_data, file_label):
        # If key is valid and does not contain segmentation data, create figure and add title
        if key_matches(key, args.flow_keys + args.rgb_keys + args.other_non_rgb_keys):
            plt.figure()
            plt.title("{} in {}".format(key, file_label))

        if key_matches(key, args.flow_keys):
            try:
                # This import here is ugly, but else everytime someone uses this script it demands opencv and the progressbar
                sys.path.append(os.path.join(os.path.dirname(__file__)))
                from utils import flow_to_rgb
            except ImportError:
                raise ImportError("Using .hdf5 containers, which contain flow images needs opencv-python and progressbar "
                                  "to be installed!")

            # Visualize optical flow
            plt.imshow(flow_to_rgb(data), cmap='jet')
        elif key_matches(key, args.segmap_keys):
            # Try to find labels for each channel in the segcolormap
            channel_labels = {}
            _, key_index = key_matches(key, args.segmap_keys, return_index=True)
            if key_index < len(args.segcolormap_keys):
                # Check if segcolormap_key for the current segmap key is configured and exists
                segcolormap_key = args.segcolormap_keys[key_index]
                if segcolormap_key in full_hdf5_data:
                    # Extract segcolormap data
                    segcolormap = json.loads(np.array(full_hdf5_data[segcolormap_key]).tostring())
                    if len(segcolormap) > 0:
                        # Go though all columns, we are looking for channel_* ones
                        for colormap_key, colormap_value in segcolormap[0].items():
                            if colormap_key.startswith("channel_") and colormap_value.isdigit():
                                channel_labels[int(colormap_value)] = colormap_key[len("channel_"):]

            # Make sure we have three dimensions
            if len(data.shape) == 2:
                data = data[:, :, None]
            # Go through all channels
            for i in range(data.shape[2]):
                # Try to determine label
                if i in channel_labels:
                    channel_label = channel_labels[i]
                else:
                    channel_label = i

                # Visualize channel
                plt.figure()
                plt.title("{} / {} in {}".format(key, channel_label, file_label))
                plt.imshow(data[:, :, i], cmap='jet')

        elif key_matches(key, args.other_non_rgb_keys):
            # Make sure the data has only one channel, otherwise matplotlib will treat it as an rgb image
            if len(data.shape) == 3:
                if data.shape[2] != 1:
                    print("Warning: The data with key '" + key + "' has more than one channel which would not allow using a jet color map. Therefore only the first channel is visualized.")
                data = data[:, :, 0]

            plt.imshow(data, cmap='summer')
        elif key_matches(key, args.rgb_keys):
            plt.imshow(data)
Пример #5
0
def vis_data(key, data, full_hdf5_data, file_label):
    # If key is valid and does not contain segmentation data, create figure and add title
    if key in args.flow_keys + args.rgb_keys + args.other_non_rgb_keys:
        plt.figure()
        plt.title("{} in {}".format(key, file_label))

    if key in args.flow_keys:
        # Visualize optical flow
        plt.imshow(flow_to_rgb(data), cmap='jet')
    elif key in args.segmap_keys:
        # Try to find labels for each channel in the segcolormap
        channel_labels = {}
        if args.segmap_keys.index(key) < len(args.segcolormap_keys):
            # Check if segcolormap_key for the current segmap key is configured and exists
            segcolormap_key = args.segcolormap_keys[args.segmap_keys.index(
                key)]
            if segcolormap_key in full_hdf5_data:
                # Extract segcolormap data
                segcolormap = json.loads(
                    np.array(full_hdf5_data[segcolormap_key]).tostring())
                if len(segcolormap) > 0:
                    # Go though all columns, we are looking for channel_* ones
                    for colormap_key, colormap_value in segcolormap[0].items():
                        if colormap_key.startswith(
                                "channel_") and colormap_value.isdigit():
                            channel_labels[int(colormap_value)] = colormap_key[
                                len("channel_"):]

        # Make sure we have three dimensions
        if len(data.shape) == 2:
            data = data[:, :, None]
        # Go through all channels
        for i in range(data.shape[2]):
            # Try to determine label
            if i in channel_labels:
                channel_label = channel_labels[i]
            else:
                channel_label = i

            # Visualize channel
            plt.figure()
            plt.title("{} / {} in {}".format(key, channel_label, file_label))
            plt.imshow(data[:, :, i], cmap='jet')

    elif key in args.other_non_rgb_keys:
        # Make sure the data has only one channel, otherwise matplotlib will treat it as an rgb image
        if len(data.shape) == 3:
            if data.shape[2] != 1:
                print(
                    "Warning: The data with key '" + key +
                    "' has more than one channel which would not allow using a jet color map. Therefore only the first channel is visualized."
                )
            data = data[:, :, 0]

        plt.imshow(data, cmap='jet')
    elif key in args.rgb_keys:
        plt.imshow(data)
Пример #6
0
def process_img(img, key):
    if 'depth' in key or 'seg' in key:
        img = img.astype(np.float)
        img -= np.min(img)
        max_val = np.max(img)
        if max_val != np.inf:
            img /= max_val
        else:
            img /= np.max(img[img != np.inf])
        if len(img.shape) == 3:
            img = img[:, :, 0]
    elif 'flow' in key:
        img = flow_to_rgb(img)
    return img
Пример #7
0
def vis_data(key, data, full_hdf5_data, file_label):
    # If key is valid and does not contain segmentation data, create figure and add title
    if key in args.flow_keys + args.rgb_keys + args.other_non_rgb_keys:
        plt.figure()
        plt.title("{} in {}".format(key, file_label))

    if key in args.flow_keys:
        # Visualize optical flow
        plt.imshow(flow_to_rgb(data), cmap='jet')
    elif key in args.segmap_keys:
        # Try to find labels for each channel in the segcolormap
        channel_labels = {}
        if args.segmap_keys.index(key) < len(args.segcolormap_keys):
            # Check if segcolormap_key for the current segmap key is configured and exists
            segcolormap_key = args.segcolormap_keys[args.segmap_keys.index(key)]
            if segcolormap_key in full_hdf5_data:
                # Extract segcolormap data
                segcolormap = json.loads(np.array(full_hdf5_data[segcolormap_key]).tostring())
                if len(segcolormap) > 0:
                    # Go though all columns, we are looking for channel_* ones
                    for colormap_key, colormap_value in segcolormap[0].items():
                        if colormap_key.startswith("channel_") and colormap_value.isdigit():
                            channel_labels[int(colormap_value)] = colormap_key[len("channel_"):]

        # Go through all channels
        for i in range(data.shape[2]):
            # Try to determine label
            if i in channel_labels:
                channel_label = channel_labels[i]
            else:
                channel_label = i

            # Visualize channel
            plt.figure()
            plt.title("{} / {} in {}".format(key, channel_label, file_label))
            plt.imshow(data[:, :, i], cmap='jet')

    elif key in args.other_non_rgb_keys:
        plt.imshow(data, cmap='jet')
    elif key in args.rgb_keys:
        plt.imshow(data)