def analizeXMBlobs(listXMarkers): listXMarkers = inA.resizeAll(listXMarkers) if len(listXMarkers) != 6: return 'Problem to find all tests' listBinaryXMarkers = getXMarkersBinary(listXMarkers) listXMarkersBlobs = getXMarkersBlobs(listBinaryXMarkers) control = listXMarkers[5] if(isinstance(listXMarkersBlobs, str)): #If string received return listXMarkersBlobs statsH, statsS, statsV = inA.controlStats(control) #Hue and Saturation control stats dict_test = dict() markerNames = ["ESAT6","CFP10","RV1681","P24","H2", "Control"] for i,img in enumerate(listXMarkersBlobs): blobs = inA.blobDetect(img) dict_test[markerNames[i] + "_blobs"] = len(blobs) dict_test[markerNames[i] + "_area"] = inA.areaEstimation(blobs) dict_test[markerNames[i] + "_area_color"] = inA.colorSegmentation(listXMarkers[i], statsH, statsS)[2] #Resultado algoritmo conteo blobs dict_test[markerNames[i] + "_result_blobs"] = inA.blobAnalysis(listBinaryXMarkers[i], blobs) ''' #Resultado algoritmo areas de blobs dict_test[markerNames[i] + "_result_area"] = inA.areaAnalysis(listBinaryXMarkers[i], dict_test[markerNames[i] + "_area"], i) ''' #Resultado algoritmo areas de blobs (1 Solo Blob siempre es negativo) dict_test[markerNames[i] + "_result_area"] = inA.areaAnalysis(listBinaryXMarkers[i], blobs, dict_test[markerNames[i] + "_area"], i) dict_test['tb_result_area'] = inA.tbDiagnostic(dict_test[markerNames[0]+ "_result_area"], dict_test[markerNames[1]+ "_result_area"], dict_test[markerNames[2]+ "_result_area"]) return dict_test
# Checkpoint #cv2.imwrite(str(i) + 'indRespy.png', cv2.cvtColor(test,cv2.COLOR_RGB2BGR)) plt.show() if (not batch): for i, img in enumerate(listKMeansTests): plt.subplot(321 + i), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) # Checkpoint #cv2.imwrite(str(i) + 'indRespy.png', cv2.cvtColor(img,cv2.COLOR_RGB2BGR)) plt.show() # %% # Blob detection listBlobs = [] for i, img in enumerate(listKMeansTestsBina): imgCopy = img.copy() blobs = inA.blobDetect(img) listBlobs.append(blobs) if (not batch): if (operator.mod(i, 2) != 0): # Print two by line print("Blobs detected: " + str(len(listBlobs[i - 1])) + " Blobs detected: " + str(len(listBlobs[i]))) plt.subplot(321 + i), plt.imshow(inA.drawBlobs(imgCopy, blobs), 'gray') plt.show() # Test results using blobs for i, img in enumerate(listTestsBinary): if (operator.mod(i, 2) != 0): # Print two by line if (not batch): print("Result: " + inA.blobAnalysis(img, listBlobs[i - 1]) + " Area: " + str(round(inA.areaEstimation(listBlobs[i - 1]), 2)) + "\t Result: " + inA.blobAnalysis(img, listBlobs[i]) +
kMeansReconstructedReshaped, 1) # Grayscale image imgGray = cv2.cvtColor(kMeansReconstructedReshaped, cv2.COLOR_BGR2GRAY) # Thresholded image _, imgBina = cv2.threshold(imgGray, 160, 255, cv2.THRESH_BINARY) # And operation with mask imgBinaMask = inA.andOperation(imgBina, mask) # Opening of the final image (Erotion followed by dilation) kernel = np.ones((1, 1), np.uint8) imgBinaMaskOpen = cv2.morphologyEx(imgBinaMask, cv2.MORPH_OPEN, kernel) # Image preprocessing => FINISH # Blob analysis => START blobs = inA.blobDetect(imgBinaMaskOpen) area = round(inA.areaEstimation(blobs), 2) diagnosis = inA.areaAnalysis2(imgBina, blobs, area, marker['marker']) # Blob analysis => FINISH # Diagnosis comparison => START kMeansStats = {'diagnosis': diagnosis} dbStats = {'diagnosis': marker['diagnostic']} if (kMeansStats['diagnosis'] == dbStats['diagnosis']): results['coincidences'] += 1 elif (kMeansStats['diagnosis'] != dbStats['diagnosis']): results['errors'] += 1 # Diagnosis comparison => FINISH # Image shows (Only one per execution)
if count > 0: if(isinstance(originalImage, str)): print(originalImage) continue else: # Image preprocessing => START imgBina = pP.contourBinarizationOtsu( originalImage, 3, 3, 45, 4, Gs=0, inverse=False, mean=True) imgBinMask = inA.andOperation(imgBina, mask) imgBinMaskMorph = inA.erosionDilation(imgBinMask, 3) imgBinMaskMorphInv = cv2.bitwise_not(imgBinMaskMorph) # Image preprocessing => FINISH # Blob analysis => START imgBinaMaskInvMorphCopy = imgBinMaskMorphInv.copy() blobs = inA.blobDetect(imgBinMaskMorphInv) area = round(inA.areaEstimation(blobs), 2) diagnosis = inA.areaAnalysis2( imgBina, blobs, area, marker['marker']) # Blob analysis => FINISH # Diagnosis comparison => START blobsStats = { 'diagnosis': diagnosis } dbStats = { 'diagnosis': marker['diagnostic'] } if (blobsStats['diagnosis'] == dbStats['diagnosis']): results['coincidences'] += 1 elif (blobsStats['diagnosis'] != dbStats['diagnosis']):