【问题标题】:how to center MRI images如何使 MRI 图像居中
【发布时间】:2018-11-04 01:59:25
【问题描述】:

我从事核磁共振检查。问题是图像并不总是居中。此外,患者身体周围常有黑色条带。

我希望能够像这样移除黑色边框并将患者的身体居中:

我已经尝试通过读取像素表来确定患者身体的边缘,但我还没有得出任何非常确凿的结论。

事实上,我的解决方案仅适用于 50% 的图像...我没有看到任何其他方法...

开发环境:Python3.7 + OpenCV3.4

【问题讨论】:

  • 与您的问题无关 - 您正在阅读 dicom 文件吗?

标签: python opencv image-processing


【解决方案1】:

我不确定这是执行此操作的标准或最有效的方法,但它似乎有效:

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

你最终得到的是这样的:

【讨论】:

  • 确实你做得比我好得多,你的解决方案几乎适用于 100% 的图像!非常感谢您的回答对我有很大帮助!
【解决方案2】:

有多种方法可以做到这一点,这就是计算机视觉提示和技巧的答案。

如果质量在中心,而外面的区域总是黑色的,你可以threshold 图像,然后像你一样找到边缘像素。我会在边框上添加 10 个像素以调整阈值过程中的差异。

或者,如果正文的大小始终相似,you can find the centroid of the blob (white area in the threshold image), and then crop a fixed area around it

【讨论】:

  • 我曾想过使用类似的东西,但我是图像处理的初学者,我没有正确的想法。谢谢你的回答
猜你喜欢
  • 2022-01-04
  • 2014-02-28
  • 2016-04-23
  • 1970-01-01
  • 2021-03-25
  • 2020-11-04
  • 1970-01-01
  • 2015-04-04
相关资源
最近更新 更多