小编Cod*_*ict的帖子

乳房 X 光检查中最大轮廓的 OpenCV 分割

这可能是一个有点太“笼统”的问题,但是如何执行灰度图像分割并保持最大轮廓?我试图从乳房X光照片中消除背景噪音(即标签),但我没有成功。这是原始图像:

在此输入图像描述

首先,我应用了 AGCWD 算法(基于论文“Efficient Contrast Enhancement using Adaptive Gamma Correction With Weighting Distribution”)以获得更好的图像像素对比度,如下所示: 在此输入图像描述

之后,我尝试执行以下步骤:

使用OpenCV的KMeans聚类算法进行图像分割:

enhanced_image_cpy = enhanced_image.copy()
reshaped_image = np.float32(enhanced_image_cpy.reshape(-1, 1))

number_of_clusters = 10
stop_criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.1)

ret, labels, clusters = cv2.kmeans(reshaped_image, number_of_clusters, None, stop_criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
clusters = np.uint8(clusters)
Run Code Online (Sandbox Code Playgroud)

Canny 边缘检测:

removed_cluster = 1

canny_image = np.copy(enhanced_image_cpy).reshape((-1, 1))
canny_image[labels.flatten() == removed_cluster] = [0]

canny_image = cv2.Canny(canny_image,100,200).reshape(enhanced_image_cpy.shape)
show_images([canny_image])
Run Code Online (Sandbox Code Playgroud)

查找并绘制轮廓:

initial_contours_image = np.copy(canny_image)
initial_contours_image_bgr = cv2.cvtColor(initial_contours_image, cv2.COLOR_GRAY2BGR)
_, thresh = cv2.threshold(initial_contours_image, 50, 255, 0)
contours, hierarchy …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing image-segmentation

2
推荐指数
1
解决办法
1173
查看次数

在 GoLang 中将图像转换为 Base64

我正在尝试使用 Base64 编码转换图像并将其保存到数据库中。这是我的程序:

  1. HTML 页面显示一个用于浏览图像的按钮
  2. 图像正在通过以下代码进行处理:
func HandleUpload(w http.ResponseWriter, r *http.Request, formFileName string) (string, string, string, error) {
    // Maximum upload of 10 MB files
    r.ParseMultipartForm(1 << 2)

    file, handler, err := r.FormFile(formFileName)
    if err != nil {
        // If there is an error that means form is empty. Return nil for err in order
        // to validate result as required.
        return "", "", "", nil
    }

    defer file.Close()

    fmt.Printf("Uploaded File: %+v\n", handler.Filename)
    fmt.Printf("File Size: %+v\n", handler.Size)
    fmt.Printf("MIME Header: %+v\n", …
Run Code Online (Sandbox Code Playgroud)

postgresql base64 go

2
推荐指数
1
解决办法
1万
查看次数

无法在 Python 中解析 XML 文件 - xml.etree.ElementTree.ParseError

我正在尝试使用 Python 的 xml 模块解析 XML 文件中的信息。问题是,当我指定文件列表并开始解析策略时,在(据称)成功解析第一个文件后,我收到以下错误:

Parsing 20586908.xml ..
Parsing 20586934.xml ..


Traceback (most recent call last):
  File "<ipython-input-72-0efdae22e237>", line 11, in parse
    xmlTree = ET.parse(xmlFilePath, parser = self.parser)
  File "C:\Users\StefanCepa995\miniconda3\envs\dl4cv\lib\xml\etree\ElementTree.py", line 1202, in parse
    tree.parse(source, parser)
  File "C:\Users\StefanCepa995\miniconda3\envs\dl4cv\lib\xml\etree\ElementTree.py", line 601, in parse
    parser.feed(data)
xml.etree.ElementTree.ParseError: parsing finished: line 1755, column 0
Run Code Online (Sandbox Code Playgroud)

这是我用来解析 XML 文件的代码:

class INBreastXMLParser:
    def __init__(self, xmlRootDir):
        self.parser         = ET.XMLParser(encoding="utf-8")
        self.xmlAnnotations = [os.path.join(root, f)
                                   for root, dirs, files in os.walk(xmlRootDir)
                                              for f in files if f.endswith('.xml')]
    def …
Run Code Online (Sandbox Code Playgroud)

python xml elementtree xml-parsing

1
推荐指数
1
解决办法
6302
查看次数