0

所以我想使用 GAN 从超声图像中模拟 CT 图像,我目前正在准备数据。

根据超声波的性质,这些图像以锥形形式存储: 在此处输入图像描述

但我想要的是以下形式的图像: 在此处输入图像描述

我相信以这种方式模拟 CT 图像更容易。

我正在使用简单的 ITK。我想这应该是一个常见的转变。是否有我不知道的 sITK 过滤器?还是有其他简单的方法来进行这种转换?

4

1 回答 1

0

单应性想法不起作用,所以这不能作为答案,但希望其中一些仍然有用。

我基本上针对六个关键点,并试图纠正它们。然而,单应性没有处理顶部和底部的圆柱曲线。

在此处输入图像描述

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);
于 2021-01-28T17:03:12.480 回答