import re
from numpy import *
import cv2
import numpy as np
import os
import json
def getlabelingdata(file):
with open(file, encoding='utf-8') as f:
contents = json.load(f)
# print(contents)
dict = contents['markResult']['objects']
dict = dict[0]
dict = dict['features']
dict = dict[0]
dict = dict['geometry']['coordinates']
labelpoint = np.array(dict).astype(np.float32)
return labelpoint
flog = open('/data/cholangiocarcinoma/processed/yuxi_label_data/log.txt', 'w')
LNP = 'P'
root = '/data/cholangiocarcinoma/processed/datatang_label_data/P/json/'
for eachfile in os.listdir(root):
hsi_file = root + eachfile
hsi_file = '/data/cholangiocarcinoma/processed/datatang_label_data/P/json/h2-3-20x-roi6.png.json'
eachfile = os.path.split(hsi_file)[1]
if 'png.json' in hsi_file:
name = eachfile.split('.')
rgb_name = name[0] + '.' + name[2]
rgb_file = root + rgb_name
hsi_points = getlabelingdata(hsi_file)
rgb_points = getlabelingdata(rgb_file)
hsi_img_path = '/data_ssd/zhangmingjie/pytorch-3dunet-master-zr_20210621/visualization/' + LNP + '/' + name[0] + '_hsi_band_30.png'
rgb_img_path = '/data/cholangiocarcinoma/processed/' + LNP + '/img_rgb_resize_w1365h1024/' + name[0] + '.jpg'
hsi_img_save_path = '/data/cholangiocarcinoma/processed/datatang_label_data/check/re_re/' + name[0] + '.png'
rgb_img_save_path = '/data/cholangiocarcinoma/processed/datatang_label_data/check/re_re/' + name[0] + '_registered.jpg'
#re_label_hsi_img_save_path = '/data/cholangiocarcinoma/processed/yuxi_label_data/labeling_data/' + LNP + '/' + sampleName + '.bmp'
#re_label_rgb_img_save_path = '/data/cholangiocarcinoma/processed/yuxi_label_data/labeling_data/' + LNP + '/' + sampleName + '.jpg'
hsi_img = cv2.imread(hsi_img_path)
rgb_img = cv2.imread(rgb_img_path)
rgb_img = np.flip(rgb_img, 0)
cv2.imwrite(hsi_img_save_path, hsi_img)
#cv2.imwrite(re_label_hsi_img_save_path, hsi_img)
#cv2.imwrite(re_label_rgb_img_save_path, rgb_img)
M = cv2.getAffineTransform(hsi_points, rgb_points)
dst = np.zeros([1024, 1280, 3], dtype=np.uint8)
for i in range(1024):
for j in range(1280):
new_x = int(j * M[0][0] + i * M[0][1] + M[0][2] + 0.5)
new_y = int(j * M[1][0] + i * M[1][1] + M[1][2] + 0.5)
if new_x >= 0 and new_x < 1365 and new_y >= 0 and new_y < 1024:
dst[i, j, :] = rgb_img[new_y, new_x, :]
cv2.imwrite(rgb_img_save_path, dst)
break
flog.close()
图像配准 仿射变换
最新推荐文章于 2024-03-19 11:20:51 发布