如何使MRI图像居中

3
我从事MRI的工作。问题在于图像并不总是居中的。此外,患者身体周围经常有黑边。
我希望能够像这样去除黑边并将患者的身体居中: enter image description here enter image description here 我已经尝试通过读取像素表来确定患者身体的边缘,但没有得出什么很明确的结论。
实际上,我的解决方案只适用于50%的图像...我没有看到其他方法...
开发环境:Python3.7 + OpenCV3.4

与您的问题无关 - 您是否正在读取DICOM文件? - Abbas
2个回答

4

我不确定这是标准或最有效的方法,但它似乎能够工作:

# Load image as grayscale (since it's b&w to start with)
im = cv2.imread('im.jpg', cv2.IMREAD_GRAYSCALE)

# Threshold it. I tried a few pixel values, and got something reasonable at min = 5
_,thresh = cv2.threshold(im,5,255,cv2.THRESH_BINARY)

# Find contours:
im2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

# Put all contours together and reshape to (_,2).
# The first "column" will be your x values of your contours, and second will be y values
c = np.vstack(contours).reshape(-1,2)

# Extract the most left, most right, uppermost and lowermost point
xmin = np.min(c[:,0])
ymin = np.min(c[:,1])
xmax = np.max(c[:,0])
ymax = np.max(c[:,1])

# Use those as a guide of where to crop your image
crop = im[ymin:ymax, xmin:xmax]

cv2.imwrite('cropped.jpg', crop)

你最终得到的是这个:

cropped_image


(该内容为关于IT技术的图片,无法翻译)

你的解决方案比我做得好多了,几乎可以适用于100%的图像!非常感谢你的答案,对我帮助很大! - Jhon Snow

2

我曾考虑过使用类似的东西,但我是图像处理方面的初学者,没有正确的想法。谢谢你的回答。 - Jhon Snow

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接