我有一个microscopy image,需要计算红色显示的面积。我们的想法是构建一个函数,返回右侧照片上红线内的区域(浮点值,X mm²)。
由于我几乎没有图像处理的经验,我不知道如何处理这个(可能很愚蠢的)问题,所以我正在寻求帮助。其他图像示例非常类似,只有1个聚集在一起的“兴趣区”靠近中心。
我习惯于用python编码,并且已经使用软件ImageJ一段时间了。
任何python包、软件、参考书目等都应该有所帮助。
谢谢!
编辑:我手工制作的红色示例只是为了让人们理解我想要什么。检测“感兴趣区域”必须在代码内部完成。
发布于 2021-08-05 22:03:38
精明,形态变换和轮廓可以提供一个不错的结果。
尽管它可能需要根据输入图像进行一些微调。
import numpy as np
import cv2
# Change this with your filename
image = cv2.imread('test.png', cv2.IMREAD_GRAYSCALE)
# You can fine-tune this, or try with simple threshold
canny = cv2.Canny(image, 50, 580)
# Morphological Transformations
se = np.ones((7,7), dtype='uint8')
image_close = cv2.morphologyEx(canny, cv2.MORPH_CLOSE, se)
contours, _ = cv2.findContours(image_close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
# Create black canvas to draw area on
mask = np.zeros(image.shape[:2], np.uint8)
biggest_contour = max(contours, key = cv2.contourArea)
cv2.drawContours(mask, biggest_contour, -1, 255, -1)
area = cv2.contourArea(biggest_contour)
print(f"Total area image: {image.shape[0] * image.shape[1]} pixels")
print(f"Total area contour: {area} pixels")
cv2.imwrite('mask.png', mask)
cv2.imshow('img', mask)
cv2.waitKey(0)
# Draw the contour on the original image for demonstration purposes
original = cv2.imread('test.png')
cv2.drawContours(original, biggest_contour, -1, (0, 0, 255), -1)
cv2.imwrite('result.png', original)
cv2.imshow('result', original)
cv2.waitKey(0)该代码生成以下输出:
Total area image: 332628 pixels
Total area contour: 85894.5 pixels剩下的唯一要做的就是将像素转换为您喜欢的测量值。
下面是两张演示图片。
发布于 2021-08-05 20:30:16
我对这个话题不太了解,但它看起来和这个问题非常相似,这个问题有两个很好的答案:
https://stackoverflow.com/questions/68673084
复制相似问题