def overlap(image, settings: Settings): max = np.max(image) channel1 = 0 channel2 = 1 threshold = settings.overlapthreshold * max overch1 = [ 1 if i == True else 0 for i in (image[:, :, channel1] > threshold).flatten() ] overch2 = [ 1 if i == True else 0 for i in (image[:, :, channel2] > threshold).flatten() ] both = np.add(overch2, overch1) newimage = [max if i == 2 else 0 for i in both] newimage = np.array(newimage).reshape((image.shape[0], image.shape[1])) info = { "Postprocessing": "Overlapping of Channel {0} and {1}".format( settings.getMappedChannelNames()[channel1], settings.getMappedChannelNames()[channel2]) } return newimage, info
def settingsFileToSettings(filepath: str) -> Settings: # TODO: Implement # TODO: make best fit settings search automatically settings = Settings() return settings
def sobelunblurred(image, settings: Settings): image = image[:, :, settings.selectiveChannel] sobelx = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=5) info = { "Postprocessing": "Sobel of Channel {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return sobelx, info
def channelintensity(image, settings: Settings): logging.info("Only display channel {0}".format(settings.selectiveChannel)) images = image[:, :, settings.selectiveChannel] info = { "Postprocessing": "Intensity of {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return images, info
def sobelblurred(image, settings: Settings): image = image[:, :, settings.selectiveChannel] blurred = cv2.GaussianBlur(image, (3, 3), 3) sobelx = cv2.Sobel(blurred, cv2.CV_64F, 1, 0, ksize=5) info = { "Postprocessing": "Sobel of Blurred Channel {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return sobelx, info
def laplace(image, settings: Settings): logging.info("LaPlacian of Selective Channel") image = image[:, :, settings.selectiveChannel] laplacian = cv2.Laplacian(image, cv2.CV_64F) info = { "Postprocessing": "La Placian of Channel {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return laplacian, info
def canny(image, settings: Settings): cvimage = image[:, :, settings.selectiveChannel] blured = cv2.GaussianBlur(cvimage, (3, 3), 3) sobelx = cv2.Canny(blured, 100, 200) info = { "Postprocessing": "Canny Edge of Channel {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return sobelx, info
def color(image, settings: Settings): imager = np.zeros(image.shape, np.uint8) imager[:, :, settings.selectiveChannel] = image[:, :, settings.selectiveChannel] info = { "Postprocessing": "Selective color of Channel {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return imager, info
def __init__(self): super(Plugin, self).__init__() logging.info("Plugin initialized") self.colours = iter( (rand_cmap(200, first_color_black=False)(np.linspace(0, 1, 200)))) self.roiindex = iter(list(range(100))) self.stageindex = iter(list(range(100))) self.settings = Settings() self.activeSample = Sample() self.standardErrorRaiser = None
def prewitt(image, settings: Settings): logging.info("Only display channel {0}".format(settings.selectiveChannel)) gray = image[:, :, settings.selectiveChannel] kernelx = np.array([[1, 1, 1], [0, 0, 0], [-1, -1, -1]]) kernely = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]) img_gaussian = cv2.GaussianBlur(gray, (3, 3), 0) img_prewittx = cv2.filter2D(img_gaussian, -1, kernelx) img_prewitty = cv2.filter2D(img_gaussian, -1, kernely) images = img_prewittx + img_prewitty info = { "Postprocessing": "Intensity of {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return images, info
def robertoperator(image, settings: Settings): logging.info("Only display channel {0}".format(settings.selectiveChannel)) image = image[:, :, settings.selectiveChannel] image = np.asarray(image, dtype="int32") roberts_cross_v = np.array([[0, 0, 0], [0, 1, 0], [0, 0, -1]]) roberts_cross_h = np.array([[0, 0, 0], [0, 0, 1], [0, -1, 0]]) from scipy import ndimage vertical = ndimage.convolve(image, roberts_cross_v) horizontal = ndimage.convolve(image, roberts_cross_h) output_image = np.sqrt(np.square(horizontal) + np.square(vertical)) info = { "Postprocessing": "Intensity of {0}".format( settings.getMappedChannelNames()[settings.selectiveChannel]) } return output_image, info
def saveSampleToHDF(sample: Sample, settings: Settings): rchannel, gchannel, bchannel = settings.getMappedChannelNames() filename = "Test - {0}.h5".format(rchannel) #TODO: Find good naming scheme filename = settings.seriesname import string valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) filename = ''.join(c for c in filename if c in valid_chars) filename = str(filename) + ".h5" dirname = settings.directory h5file = h5py.File(os.path.join(dirname, filename), "w") timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') h5file.attrs['Filename'] = filename h5file.attrs["Physicalsize-X"] = sample.biometa.physicalsizex h5file.attrs["Physicalsize-Y"] = sample.biometa.physicalsizey h5file.attrs["Physicalsize-X-Unit"] = sample.biometa.physicalsizexunit h5file.attrs["Physicalsize-Y-Unit"] = sample.biometa.physicalsizeyunit h5file.attrs["R"] = rchannel h5file.attrs["B"] = bchannel h5file.attrs["G"] = gchannel h5file.attrs['Creator'] = settings.name h5file.attrs['Script-Version'] = settings.version h5file.attrs['HDF5_Version'] = h5py.version.hdf5_version h5file.attrs['h5py_version'] = h5py.version.version # give the HDF5 root some more attributes h5file.attrs['File-Time'] = timestamp if settings.saveBioImageToHDF: bioimagegroup = h5file.create_group("BioImage") bioimagegroup.attrs["Unparsed-Meta"] = sample.biometa.unparsed nana = np.array(sample.bioimage.file) file = bioimagegroup.create_dataset("Numpy-Array", data=nana, compression="gzip", compression_opts=7) datagroup = h5file.create_group('Data') for key, data in sample.data.items(): dataitem = datagroup.create_group("Data " + str(data.key)) dataitem = data.getHDF(dataitem, settings) roisgroup = h5file.create_group('ROIs') for key, roi in sample.rois.items(): roiitem = roisgroup.create_group("Roi " + str(roi.key)) roiitem = roi.getHDF(roiitem, settings) transformationssgroup = h5file.create_group('Transformations') for key, transformation in sample.transformations.items(): transformationitem = transformationssgroup.create_group( "Transformation " + str(transformation.key)) transformationitem = transformation.getHDF(transformationitem, settings) stagegroup = h5file.create_group('Stages') for key, stage in sample.stages.items(): stageitem = stagegroup.create_group("Stage " + str(stage.key)) stageitem = stage.getHDF(stageitem, settings) logging.info("HDF5 Written") h5file.close()