如何将超声图像转换为模拟CT图像?
How to transform Ultrasound images for simulation of CT images?
所以我想使用 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);
所以我想使用 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);