Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Medical treatment by Python opencv

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to achieve medical treatment in Python opencv". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve medical treatment in Python opencv".

Topic description

Use opencv or other tools to write programs to achieve medical processing.

Implementation process #-*-coding: utf-8-* 'author: Ding Yi Development time: 2021-5-9 16:30'''import cv2import numpy as np# Image thinning def VThin (image, array): rows Cols = image.shape NEXT = 1 for i in range (rows): for j in range (cols): if NEXT = = 0: NEXT = 1 else: M = int (image [I, j-1]) + int (image [I, j]) + int (image [I, j + 1]) if 0

< j < cols - 1 else 1 if image[i, j] == 0 and M != 0: a = [0]*9 for k in range(3): for l in range(3): if -1 < (i - 1 + k) < rows and -1 < (j - 1 + l) < cols and image[i - 1 + k, j - 1 + l] == 255: a[k * 3 + l] = 1 sum = a[0] * 1 + a[1] * 2 + a[2] * 4 + a[3] * 8 + a[5] * 16 + a[6] * 32 + a[7] * 64 + a[8] * 128 image[i, j] = array[sum]*255 if array[sum] == 1: NEXT = 0 return imagedef HThin(image, array): rows, cols = image.shape NEXT = 1 for j in range(cols): for i in range(rows): if NEXT == 0: NEXT = 1 else: M = int(image[i-1, j]) + int(image[i, j]) + int(image[i+1, j]) if 0 < i < rows-1 else 1 if image[i, j] == 0 and M != 0: a = [0]*9 for k in range(3): for l in range(3): if -1 < (i-1+k) < rows and -1 < (j-1+l) < cols and image[i-1+k, j-1+l] == 255: a[k*3+l] = 1 sum = a[0]*1+a[1]*2+a[2]*4+a[3]*8+a[5]*16+a[6]*32+a[7]*64+a[8]*128 image[i, j] = array[sum]*255 if array[sum] == 1: NEXT = 0 return imagearray = [0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0]# 显示灰度图img = cv2.imread(r"C:UserspcDesktopvas0.png",0)cv2.imshow("img1",img)# 自适应阈值分割img2 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 17, 4)cv2.imshow('img2', img2)# 图像反色img3 = cv2.bitwise_not(img2)cv2.imshow("img3", img3)# 图像扩展img4 = cv2.copyMakeBorder(img3, 1, 1, 1, 1, cv2.BORDER_REFLECT)cv2.imshow("img4", img4)contours, hierarchy = cv2.findContours(img4, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)# 消除小面积img5 = img4for i in range(len(contours)): area = cv2.contourArea(contours[i]) if (area < 80) | (area >

10000): cv2.drawContours (img5, [contours], 0,0,-1) cv2.imshow ("img5", img5) num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats (img5, connectivity=8, ltype=None) # print (stats) s = sum (stats) img6 = np.ones (img5.shape, np.uint8) * 0for (I, label) in enumerate (np.unique (labels)): # if it is the background Ignore if label = = 0: # print ("[INFO] label: 0 (background)") continue numPixels = stats [I] [- 1] div = (stats [I] [4]) / s [4] # print (div) # to determine whether the area meets the area requirement if round (div, 3) > 0.002: color = 255img6 [labels = label] = colorcv2.imshow ("img6") Img6) # Image inverse img7 = cv2.bitwise_not (img6) # Image thinning for i in range (10): VThin (img7, array) HThin (img7, array) cv2.imshow ("img7", img7) # Edge Detection img8 = cv2.Canny (img6, 80,255) cv2.imshow ("img8", img8) # reverse grayscale image img9 = cv2.bitwise_not (img8) cv2.imshow ("img9", img9) cv2.waitKey (0) Thank you for your reading The above is the content of "how to achieve medical treatment of Python opencv". After the study of this article, I believe you have a deeper understanding of how to achieve medical treatment of Python opencv, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report