Stack Overflow Asked by Mohamed Mohsen on January 26, 2021
I want to find Connected Components in all dataset " Brain MRI Images Dataset" so when I apply cv2.CoconnectedComponentsWithStats()
method to get blobs in images it converts all dataset to only black images and doesn’t work
Note: When I apply connected components on a single image it works but in many images doesn’t work
i = 0
for image in path:
input_image = np.array(Image.open(image))
resized = cv2.resize(input_image,(512,512))
if(len(resized.shape) > 2):
# Convert From RGB to GRAYScale
gray_image = cv2.cvtColor(resized, cv2.COLOR_RGB2GRAY)
# Thresholding
T, threshold_image = cv2.threshold(gray_image,160,255,cv2.THRESH_BINARY)
# opening
kernel = np.ones((7,7), 'uint8')
open_img=cv2.morphologyEx(th2,cv2.MORPH_OPEN,kernel)
# Closing
close_img=cv2.morphologyEx(open_img,cv2.MORPH_CLOSE,kernel)
# Blobs
num_labels, labels_im, stats, centroids = cv2.connectedComponentsWithStats(threshold_image , connectivity = 4)
# Save Result
cv2.imwrite('C:/Users/moham/Desktop/Medical Image Processing Project/Result/0'+
str(i)+'.png',labeled_img)
i = i + 1
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP