Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] lut颜色随机生成 #48

Merged
merged 4 commits into from
Oct 31, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions backend/applications/interface/semantic_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import os.path as osp
from collections import Counter

import cv2
import numpy as np
import paddlers as pdrs
from paddlers.tasks.utils.visualize import get_color_map_list
from skimage.io import imsave

from applications.common.path_global import md5_name, generate_url


def get_lut():
lut = np.zeros((256, 3), dtype=np.uint8)
lut[0] = [255, 0, 0] # 红
lut[1] = [30, 255, 142] # 浅绿
lut[2] = [60, 0, 255] # 蓝
lut[3] = [255, 222, 0] # 橙黄
lut[4] = [255, 0, 255] # 粉
return lut


def execute(model_path, data_path, out_dir, test_names):
image_list = [osp.join(data_path, name) for name in test_names]
predictor = pdrs.deploy.Predictor(model_path, use_gpu=True)
pred = predictor.predict(image_list)
ims = [i['label_map'] for i in pred]
lut = get_lut()
temps = list()
for idx, im in zip(range(len(image_list)), ims):
im = lut[im]
im = np.array(get_color_map_list(np.max(im) + 1))[im]
jscslld marked this conversation as resolved.
Show resolved Hide resolved
new_name = md5_name(test_names[idx])
imsave(osp.join(out_dir, new_name), im)
temps.append(generate_url + new_name)
Expand Down