Skip to content

how to output the gray image without random.randint? #18

@zhou-rui1

Description

@zhou-rui1

Hi, I want to output the gray image for the binary classfication, how should I edit it?

I try to edit this part but failed:
`random.seed(0)
class_colors = [(random.randint(0, 255), random.randint(
0, 255), random.randint(0, 255)) for _ in range(5000)]

def convert_seg_gray_to_color(input, n_classes, output_path=None, colors=class_colors):
if isinstance(input, six.string_types):
seg = cv2.imread(input, flags=cv2.IMREAD_GRAYSCALE)
elif type(input) is np.ndarray:
assert len(input.shape) == 2, "Input should be h,w "
seg = input

height = seg.shape[0]
width = seg.shape[1]

seg_img = np.zeros((height, width, 3))

for c in range(n_classes):
	seg_arr = seg[:, :] == c
	seg_img[:, :, 0] += ((seg_arr) * colors[c][0]).astype('uint8')
	seg_img[:, :, 1] += ((seg_arr) * colors[c][1]).astype('uint8')
	seg_img[:, :, 2] += ((seg_arr) * colors[c][2]).astype('uint8')

if output_path:
	cv2.imwrite(output_path, seg_img)
else:
	return seg_img`

Can you give me some guidance?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions