def getTransformedDataset(self, imageCollections, onlyPatchzone=True): dataset = [] namesObservations = [] coordinates = [] for imageCollection in imageCollections: imageCount = 0 for image in imageCollection: im = image imageName = imageCollection.files[imageCount] imageWorker = RGBImageWorker(im, convert=True) (binaryImageWorkerCenters, HEDAVWorker, BRVLWorker, binaryImageWorker) = imageWorker.getBinaryImage() workerPack = [imageWorker, BRVLWorker, HEDAVWorker] generalStatistics = imageWorker.getGeneralStatistics( hara=True, zern=False) centers = binaryImageWorkerCenters.getCenters() print len(centers) for center in centers: print "center" binaryPatch = binaryImageWorker.getPatch( center, self.patchSize) binaryStatistics = binaryPatch.getGeneralStatistics() namesObservations.append(imageName) coordinates.append([center[0], center[1]]) observation = binaryStatistics observation.extend(copy.deepcopy(generalStatistics)) if onlyPatchzone: for worker in workerPack: patch = worker.getPatch(center, self.patchSize) observation.extend( patch.getGeneralStatistics( hara=True, zern=True, tamura=False, only1D=patch.image[binaryPatch.image])) observation.extend( patch.getGeneralStatistics(hara=True, zern=True, tamura=True)) else: for patchsize in range(1, self.patchSize, 10): for worker in workerPack: patch = worker.getPatch(center, patchsize) observation.extend( patch.getGeneralStatistics()) patch = imageWorker.getPatch(center, self.patchSize) observation.extend( patch.getGeneralStatistics(hara=True, zern=True, tamura=True)) print len(observation) dataset.append(observation) print imageName imageCount += 1 dataset = np.array(dataset) return (namesObservations, coordinates, dataset)
def getTransformedDatasetChecking(self, imageCollections): dataset = [] namesObservations = [] coordinates = [] totalMitoticPoints = 0 for imageCollection in imageCollections: imageCount = 0 missedCount = 0 totalCount = 0 for image in imageCollection: im = image imageName = imageCollection.files[imageCount] if not "10" in imageName: imageCount += 1 continue imageWorker = RGBImageWorker(im, convert=True) (binaryImageWorkerCenters, _, _, binaryImageWorker) = imageWorker.getBinaryImage() centers = binaryImageWorkerCenters.getCenters() count = 0 (incMissedCount, incTotalCount, incTotalMitoticPoints) = self.checkMissedCount( imageName, centers) totalCount += incTotalCount totalMitoticPoints += incTotalMitoticPoints missedCount += incMissedCount for center in centers: binaryPatch = binaryImageWorker.getPatch( center, self.patchSize) binaryStatistics = binaryPatch.getGeneralStatistics() count += 1 namesObservations.append(imageName) coordinates.append([center[0], center[1]]) observation = binaryStatistics dataset.append(observation) print "Candidates: %d" % (count) print "Missed this patient: %d" % (missedCount) if totalCount != 0: print "Missed ratio this patient: %f" % ( (missedCount + 0.0) / (totalCount + 0.0)) print "Total number of candidates: %d" % (len(dataset)) print "Total number of mitotic points: %d" % totalMitoticPoints print "Total ratio mitotic/candidate: %f" % ( (0.0 + totalMitoticPoints) / (0.0 + len(dataset))) print imageName imageCount += 1 return (np.array(namesObservations), np.array(coordinates), np.array(dataset))
def saveImages(self): for index in range(self.length): image = self.getImageFromName(self.namesObservations[index]) imageWorker = RGBImageWorker(image, self.rows, self.columns) patch = imageWorker.getPatch(self.coordinates[index], self.patchSize) reducedFileName = "%s_%d.tif" % (Utils.getFolderName( self.namesObservations[index]), index) if self.targetVector is None: fileName = os.path.join(data_io.get_testing_folder(), data_io.get_test_folder(), reducedFileName) elif self.targetVector[index] == 1: fileName = os.path.join(data_io.get_training_folder(), data_io.get_positive_folder(), reducedFileName) else: fileName = os.path.join(data_io.get_training_folder(), data_io.get_negative_folder(), reducedFileName) io.imsave(fileName, patch.image)