我正在处理一些X射线图像,我想从图像中检测和分割感兴趣的区域
考虑输入图像
我想检测图像中的方形形状,如图像中突出显示的那样
输出:感兴趣的区域看起来会像这样
这是我的代码,到目前为止我已经完成了
import cv2
import numpy as np
import pandas as pd
import os
from PIL import Image
import matplotlib.pyplot as plt
from skimage.io import imread, imshow
img = cv2.imread('image.jpg',0)
imshow(img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imshow(gray)
equ = cv2.equalizeHist(img)
imshow(equ)
img_resize = cv2.resize(img, (300, 300))
print(img_resize.shape)
figure_size = 9
new_image_gauss = cv2.GaussianBlur(img_resize, (figure_size, figure_size),0)
imshow(new_image_gauss)
img_edge = cv2.Canny(equ,100,200)
# show the image edges on the newly created image window
imshow(img_edge)
kernel = np.ones((5,5), np.uint8)
img_erosion = cv2.erode(img_edge, kernel, iterations=1)
img_dilation = cv2.dilate(img_edge, kernel, iterations=1)
imshow(img_erosion)
我得到的结果
请引导我
短暂性脑缺血发作
有一件事可能会有所帮助,那就是在进行精明的边缘检测之前,先对图像进行形态学梯度处理,以强调Python OpenCV中的边缘
输入:
相关问题 更多 >
编程相关推荐