python - 如何转换超声图像以模拟 CT 图像?
问题描述
所以我想使用 GAN 从超声图像中模拟 CT 图像,我目前正在准备数据。
我相信以这种方式模拟 CT 图像更容易。
我正在使用简单的 ITK。我想这应该是一个常见的转变。是否有我不知道的 sITK 过滤器?还是有其他简单的方法来进行这种转换?
解决方案
单应性想法不起作用,所以这不能作为答案,但希望其中一些仍然有用。
我基本上针对六个关键点,并试图纠正它们。然而,单应性没有处理顶部和底部的圆柱曲线。
import cv2
import numpy as np
# load image
img = cv2.imread("original.png");
# chop bottom (there's a weird gray band down there)
h, w = img.shape[:2];
img = img[:h-10, :, :];
# convert color
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY);
thresh = cv2.inRange(gray, 30, 255);
# split
h, w = gray.shape;
half = int(w/2);
left = gray[:,:half];
right = gray[:,half:];
# find corners
threshold = 30;
# top left
stop = False;
tl = [-1, -1];
for y in range(h):
for x in range(half):
if left[y,x] > threshold:
tl = [x, y];
stop = True;
break;
if stop:
break;
# top right
stop = False;
tr = [-1, -1];
for y in range(h):
for x in range(half):
if right[y, x] > threshold:
tr = [x + half, y];
stop = True;
break;
if stop:
break;
# bottom left
bl = [-1, -1];
stop = False;
for x in range(half):
for y in range(h):
if left[y, x] > threshold:
bl = [x, y];
stop = True;
break;
if stop:
break;
# bottom right
br = [-1, -1];
stop = False;
for x in range(half - 1, 0, -1):
for y in range(h):
if right[y, x] > threshold:
br = [x + half, y];
stop = True;
break;
if stop:
break;
# middle top
mt = [-1, -1];
for y in range(h):
if right[y, 0] > threshold:
mt = [half, y];
# middle bottom
mb = [-1, -1];
for y in range(h-1, 0, -1):
if right[y, 0] > threshold:
mb = [half, y];
# corners
corners = [];
corners.append(tl);
corners.append(tr);
corners.append(br);
corners.append(bl);
corners.append(mt);
corners.append(mb);
# draw points
for p in corners:
print(p);
tup = (p[0], p[1]);
img = cv2.circle(img, tup, 10, (0,0,255), -1);
# img = cv2.circle(img, (100, 100), 1000, (0, 0, 255), -1);
print("Res: " + str([w,h]));
# create homography destination
targets = [];
targets.append([0, 0]); # tl
targets.append([w, 0]); # tr
targets.append([w, h]); # br
targets.append([0, h]); # bl
targets.append([half, 0]); # mt
targets.append([half, h]); # mb
# make blank
corners = np.array(corners);
targets = np.array(targets);
hmat, ret = cv2.findHomography(corners, targets);
# warp image
warped = cv2.warpPerspective(img, hmat, (w, h));
# show
cv2.imshow("img", img);
cv2.imshow("thresh", thresh);
cv2.imshow("warped", warped);
cv2.waitKey(0);
推荐阅读
- mysql - 在ubuntu中安装mysql没有任何提示
- python - python中的ifelse语句类似于R
- c - 为什么在一些博客中kfifo是循环队列
- android - 如何在 textinputlayout 中动态设置大文本提示?
- c# - 更新 GUI 时冻结
- git - Git 在提交后删除被忽略的文件
- r - 删除节点并计算图论指标,R
- rest - type=Not Acceptable, status=406 错误在 Spring Rest 中用于生产应用程序/x-www-form-urlencoded
- angular - 在 Angular 组件 ngAfterViewInit 中定位 DOM 元素返回空 nodeList
- python - Python:如何在新的 def 函数中调用“容器”?