Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

so I'd like to simulate CT images from ultrasound images using GAN and I am currently working on the data preparation.

By nature of the ultrasound these images are stored in a cone shaped kind of form: enter image description here

But what I want to have is the image in the following form: enter image description here

I belief it is easier to simulate the CT image that way.

I am using simple ITK. I guess this should be a common transformation. Is there maybe a filter from sITK that I am not aware of? Or is there an other simple way to do this transformation?

question from:https://stackoverflow.com/questions/65941062/how-to-transform-ultrasound-images-for-simulation-of-ct-images

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
308 views
Welcome To Ask or Share your Answers For Others

1 Answer

The homography idea didn't work so this won't serve as an answer, but hopefully some of this is still helpful.

I basically targeted six keypoints and tried to rectify them. However, the homography didn't handle the cylindrical curve at the top and bottom.

enter image description here

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...