如何使用Python处理一系列TIF文件以区分迁移的单核细胞和背景?

发布于 2025-02-09 19:11:15 字数 399 浏览 2 评论 0原文

tif在3D凝胶中显示单核细胞

/fefala.jpg“ rel =” nofollow noreferrer“>我以前的尝试

长篇小说简短:我有一个单核细胞迁移的3D凝胶视频,该视频被细分为241个TIF文件(每个都代表了特定的时刻) 。如您在图像中所见,单核细胞(小圆圈)看起来与背景非常相似。如何使用Python处理每个TIF文件以使单核细胞从后台脱颖而出?请具体说明并解释所有必要的步骤。我的最终目标是通过OpenCV之类的东西跟踪这些细胞的运动,并随着时间的流逝绘制其轨迹。

以前,我尝试使用略微和全能图,但是我无法使单核细胞与背景不同。

TIF showing monocytes in 3D gel

my previous attempts

Long story short: I have a video of monocytes migrating in a 3D gel that is subdivided into 241 TIF files (each represents a specific moment in time). As you can see in the image, the monocytes (little circles) look very similar to the background. How can I process each TIF file using python to make the monocytes stand out from the background? Please be specific and explain all the necessary steps. My ultimate goal is to track the movement of those cells with something like OpenCV and sketch out their trajectories over time.

Previously I tried using skimage and holoviews, but I was unable to make the monocytes appear distinct from the background.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好菇凉咱不稀罕他 2025-02-16 19:11:15

我实际上并没有为您提供完整的答案,但是没有人说答案必须完整,我建议的内容可能会激发您的讨论和交流,以使您更接近解决方案...

首先,我会看您的直方图:

显然,您有一个低对比度的图像,所有亮度在64-88左右,即0..255范围的25%至33%。因此,我的第一个本能是拉伸对比度,以使64变为零,而88变为255。我在这里使用 ImageMagick 来做,因为它是概念性的,您/我们可以用 opencv << /strong>在必要时以后。

magick RPU7I.png -level 25,33% 1.jpg


然后我们可以复制该图像,模糊并减去删除低频背景功能。首先,有一个小的模糊:

magick 1.jpg \( +clone -blur 0x10 \) -compose difference -composite -auto-level 2.jpg

”在此处输入图像描述”


然后用更大的模糊:

magick 1.jpg \( +clone -blur 0x80 \) -compose difference -composite -auto-level 3.jpg

“在此处输入图像说明”


或,我们可以返回到我们的原始对比撕裂的图像1.jpg尝试以下内容:

magick 1.jpg -clahe 20x20%+128+20 result.jpg 

”在此处输入图像描述”


任何图像处理向导欢迎复制,窃取,不同意,改进,扩展,扩展,在此处编辑任何概念...

I don't actually have a complete answer for you, but nobody said answers have to be complete and what I am suggesting may stimulate discussion and an exchange of ideas that gets you nearer a solution...

Firstly, I would look at your histogram:

enter image description here

You clearly have a low-contrast image with all brightnesses in the range around 64-88, i.e. 25% to 33% of the 0..255 range. So my first instinct is to stretch the contrast so that 64 becomes zero and 88 becomes 255. I am doing it with ImageMagick here because it is conceptual and you/we can do it with OpenCV later if necessary.

magick RPU7I.png -level 25,33% 1.jpg

enter image description here


We could then copy that image, blur it and subtract to remove the low-frequency background features. Firstly with a small blur:

magick 1.jpg \( +clone -blur 0x10 \) -compose difference -composite -auto-level 2.jpg

enter image description here


Then with a larger blur:

magick 1.jpg \( +clone -blur 0x80 \) -compose difference -composite -auto-level 3.jpg

enter image description here


Or, we could go back to our original contrast-stretched image 1.jpg and try CLAHE on that:

magick 1.jpg -clahe 20x20%+128+20 result.jpg 

enter image description here


Any image-processing wizards welcome to copy, steal, disagree, improve, extend, edit any concepts here...

我不是你的备胎 2025-02-16 19:11:15

这是另一种使用除法归一化的方法,然后是Python/OpenCV中的一些动态范围拉伸。

  • 读取输入
  • 转换为灰度
  • 模糊,相对较大的sigma
  • 将模糊图像除以输入
  • 拉伸伸展动态范围
  • 保存结果

输入:

“在此处输入映像”

import cv2
import numpy as np
import skimage.exposure

# load image
img = cv2.imread("monocytes.png")

# convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# blur
blur = cv2.GaussianBlur(gray, (0,0), sigmaX=39, sigmaY=39)

# divide
divide = cv2.divide(blur, gray, scale=255)
divide = 255 - divide

# stretch
maxval = np.amax(divide)/4
stretch = skimage.exposure.rescale_intensity(divide, in_range=(0,maxval), out_range=(0,255)).astype(np.uint8)

# write result to disk
cv2.imwrite("monocytes_division.png", divide)
cv2.imwrite("monocytes_stretch.jpg", stretch)

# display it
cv2.imshow("gray", gray)
cv2.imshow("divide", divide)
cv2.imshow("stretch", stretch)
cv2.waitKey(0)
cv2.destroyAllWindows()

拉伸结果:

Here is another approach using division normalization followed by some dynamic range stretching in Python/OpenCV.

  • Read the input
  • Convert to grayscale
  • Blur with relatively large sigma
  • Divide the blurred image by the input
  • Stretch the dynamic range
  • Save the result

Input:

enter image description here

import cv2
import numpy as np
import skimage.exposure

# load image
img = cv2.imread("monocytes.png")

# convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# blur
blur = cv2.GaussianBlur(gray, (0,0), sigmaX=39, sigmaY=39)

# divide
divide = cv2.divide(blur, gray, scale=255)
divide = 255 - divide

# stretch
maxval = np.amax(divide)/4
stretch = skimage.exposure.rescale_intensity(divide, in_range=(0,maxval), out_range=(0,255)).astype(np.uint8)

# write result to disk
cv2.imwrite("monocytes_division.png", divide)
cv2.imwrite("monocytes_stretch.jpg", stretch)

# display it
cv2.imshow("gray", gray)
cv2.imshow("divide", divide)
cv2.imshow("stretch", stretch)
cv2.waitKey(0)
cv2.destroyAllWindows()

Stretched Result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文