Example #1
0
    def showmask(self, show_mask):
        MainDisplay.init_canvas(self)

        if self.skfilterButton.cget('text') == 'Hide':
            MainDisplay.show_filter(self)
        elif self.skfilterButton.cget('text') == 'Filter':
            MainDisplay.show_image(self)

        if show_mask == 0:
            if self.skmaskButton.cget('text') == 'Hide':
                self.skmaskButton.config(text='Mask')
            elif self.skmaskButton.cget('text') == 'Mask':
                MainDisplay.show_mask(self)
                self.skmaskButton.config(text='Hide')
        elif show_mask == 1:
            MainDisplay.show_mask(self)

        self._canvas.draw()

        self.eshowButton.config(text='Show')
        self.skskeletonButton.config(text='Skeleton')
        self.tshowlabelButton.config(text='Show Labels')
        self.tshowfitButton.config(text='Show Fit')

        self._overedge['enable'].set(0)
        self._overskel['enable'].set(0)
        self._overlabel['enable'].set(0)
        self._overfit['enable'].set(0)
Example #2
0
	def text_load(self, filename):

		with open(filename, 'r') as f:
			init_header = f.readline()

		if 'Channel' in init_header:
			self._img_info = FileOpen.initvar_img(self)
			self._img_info['type'].set('AFM')
			FileOpen.import_afm(self, filename)
			MainDisplay.init_canvas(self)
			MainDisplay.show_image(self)
Example #3
0
	def clearall_roiList(self):

		MainDisplay.show_overlay(self)
		ROIdisplay.noshow_roi(self)

		del self._roipath
		del self._roilabel

		self.roiListbox.delete(0, 'end')

		self._canvas.draw()
Example #4
0
    def reset(self):
        self._mat_img = 1 * self._source_img

        self._img_info['xmin'].set(0)
        self._img_info['xmax'].set(int(self._img_info['sizepix_x'].get()))
        self._img_info['ymin'].set(0)
        self._img_info['ymax'].set(int(self._img_info['sizepix_y'].get()))
        self._img_info['vmin'].set(np.min(self._mat_img.flatten()))
        self._img_info['vmax'].set(np.max(self._mat_img.flatten()))

        MainDisplay.init_canvas(self)
        MainDisplay.show_image(self)
Example #5
0
    def show_localfit(self):

        if self.tshowfitButton.cget('text') == 'Show Fit':
            self._overfit['enable'].set(1)
            self.tshowfitButton.config(text='Hide Fit')
        elif self.tshowfitButton.cget('text') == 'Hide Fit':
            self._overfit['enable'].set(0)
            self.tshowfitButton.config(text='Show Fit')

        MainDisplay.show_overlay(self)

        self.skfilterButton.config(text='Filter')
        self.skmaskButton.config(text='Mask')
Example #6
0
    def show_track(self):

        if self.tshowlabelButton.cget('text') == 'Show Labels':
            self._overlabel['enable'].set(1)
            self.tshowlabelButton.config(text='Hide Labels')
        elif self.tshowlabelButton.cget('text') == 'Hide Labels':
            self._overlabel['enable'].set(0)
            self.tshowlabelButton.config(text='Show Labels')

        MainDisplay.show_overlay(self)

        self.skfilterButton.config(text='Filter')
        self.skmaskButton.config(text='Mask')
Example #7
0
    def showskeleton(self):

        if self.skskeletonButton.cget('text') == 'Skeleton':
            self._overskel['enable'].set(1)
            self.skskeletonButton.config(text='Hide')
        elif self.skskeletonButton.cget('text') == 'Hide':
            self._overskel['enable'].set(0)
            self.skskeletonButton.config(text='Skeleton')

        MainDisplay.show_overlay(self)

        self.skfilterButton.config(text='Filter')
        self.skmaskButton.config(text='Mask')
Example #8
0
    def show(self):

        if self.eshowButton.cget('text') == 'Show':
            self._overedge['enable'].set(1)
            self.eshowButton.config(text='Hide')
        elif self.eshowButton.cget('text') == 'Hide':
            self._overedge['enable'].set(0)
            self.eshowButton.config(text='Show')

        MainDisplay.show_overlay(self)

        self.skfilterButton.config(text='Filter')
        self.skmaskButton.config(text='Mask')
Example #9
0
	def keepdelall_roi(self, keep):

		self.roiListbox.selection_clear(0, 'end')
		self.roiListbox.selection_set(0, 'end')

		if keep == 0: ROImanager.deldata_inroi(self)
		elif keep == 1: ROImanager.keepdata_inroi(self)

		ROIdisplay.noshow_roi(self)

		del self._roipath; del self._roilabel

		self.roiListbox.delete(0, 'end')

		MainDisplay.show_overlay(self)
Example #10
0
	def apply(self):
		self._overedge['size'].set(self.ove_szSpinbox.get())
		self._overedge['ecolor'].set(self.ove_ecCombobox.get())
		self._overedge['fcolor'].set(self.ove_fcCombobox.get())
		self._overskel['size'].set(self.ovs_szSpinbox.get())
		self._overskel['ecolor'].set(self.ovs_ecCombobox.get())
		self._overskel['fcolor'].set(self.ovs_fcCombobox.get())
		self._overlabel['size'].set(self.ovl_szSpinbox.get())
		self._overlabel['ecolor'].set(self.ovl_ecCombobox.get())
		self._overfit['lwidth'].set(self.ovf_lwSpinbox.get())
		self._overfit['color'].set(self.ovf_lcCombobox.get())

		MainDisplay.show_overlay(self)
		try: ROIdisplay.show_roi(self)
		except AttributeError: pass
		ImageOverlay.setstate_cpanel(self)
Example #11
0
    def crop_infostrip(self):

        if self._img_info['sizepix_y'].get() == 2207: size_infostrip = 175
        elif self._img_info['sizepix_y'].get() == 1103: size_infostrip = 85

        try:
            self._mat_img = self._source_img[:-size_infostrip, :]
            self._img_info['xmin'].set(0)
            self._img_info['xmax'].set(int(self._img_info['sizepix_x'].get()))
            self._img_info['ymin'].set(0)
            self._img_info['ymax'].set(
                int(int(self._img_info['sizepix_y'].get()) - size_infostrip))
            self._img_info['vmin'].set(np.min(self._mat_img.flatten()))
            self._img_info['vmax'].set(np.max(self._mat_img.flatten()))
            self._tracking_step = 2
        except NameError:
            self.imgcropinfoButton.config(text='Size not known')
            self.imgcropinfoButton.state(['disabled'])
        MainDisplay.init_canvas(self)
        MainDisplay.show_image(self)
Example #12
0
    def crop_selection(self):

        x1, x2 = self._a_img.get_xlim()
        y2, y1 = self._a_img.get_ylim()
        if int(x1) < 0: x1 = 0
        if int(y1) < 0: y1 = 0
        if int(x2) > self._mat_img.shape[1]: x2 = self._mat_img.shape[1]
        if int(y2) > self._mat_img.shape[0]: y2 = self._mat_img.shape[0]

        self._img_info['xmin'].set(int(x1))
        self._img_info['xmax'].set(int(x2))
        self._img_info['ymin'].set(int(y1))
        self._img_info['ymax'].set(int(y2))

        self._mat_img = self._mat_img[int(y1):int(y2), int(x1):int(x2)]
        self._img_info['vmin'].set(np.min(self._mat_img.flatten()))
        self._img_info['vmax'].set(np.max(self._mat_img.flatten()))

        MainDisplay.init_canvas(self)
        MainDisplay.show_image(self)
        self._tracking_step = 2
Example #13
0
	def image_load(self, filename):

		self._img_info = FileOpen.initvar_img(self)
		self._img_info['type'].set('STEM')
		source_image = np.array(Image.open(filename))
		self._img_info['sizepix_x'].set(source_image.shape[1])
		self._img_info['sizepix_y'].set(source_image.shape[0])

		self._colormap_options['Source'] = 'gray'
		self._menucheckCO.set(0)

		try: self._source_img = source_image[:,:,0];
		except IndexError: self._source_img = source_image[:,:]

		self._img_info['vmin'].set(np.min(source_image.flatten()))
		self._img_info['vmax'].set(np.max(source_image.flatten()))

		self._mat_img = 1*self._source_img
		MainDisplay.init_canvas(self)
		MainDisplay.show_image(self)
		self._canvas.draw()
Example #14
0
	def keepdelsel_roi(self, keep):

		if keep == 0:
			ROImanager.deldata_inroi(self)
			list_del = self.roiListbox.curselection()
		elif keep == 1:
			ROImanager.keepdata_inroi(self)
			list_del = [item for item in np.arange(self.roiListbox.size())
						if item not in self.roiListbox.curselection()]

		ROIdisplay.noshow_roi(self)

		for item in sorted(list_del, reverse=True):
			del self._roipath[item]
			del self._roilabel[item]

		for n, item in enumerate(self._roilabel):
			item.set_text(str(n+1))

		MainDisplay.show_overlay(self)

		ROIdisplay.show_roi(self)
		ROImanager.update_roiList(self)
Example #15
0
    def finalstep(self):

        MainDisplay.init_canvas(self)
        MainDisplay.show_image(self)
        self.progressBar.config(mode='determinate',
                                maximum=np.max(self._im.flatten()) + 1)
        self.progressBar['value'] = 1
        self.progressBar.update()

        ascale = self._tracking_settings['edge_ascale_current'].get()

        xm = 1 * self._xmm[self._im > 0]
        ym = 1 * self._ymm[self._im > 0]
        im = 1 * self._im[self._im > 0]
        m = self._m[self._im > 0]

        int_profile = []
        pos_profile = []
        full_profile = []
        full_position = []
        fiber_xc = []
        fiber_yc = []
        fiber_x1 = []
        fiber_x2 = []
        fiber_y1 = []
        fiber_y2 = []
        fiber_e1 = []
        fiber_e2 = []
        fiber_number = []
        fiber_slope = []
        xprofile = []
        yprofile = []

        pix_edge = int(self._tracking_settings['pixels_edge_img'].get())
        pix_back = int(
            self._tracking_settings['pixels_background_profile'].get())

        nc = 0

        for icn in np.unique(im):

            self.progressBar['value'] = icn
            self.progressBar.update()

            xcn = xm[np.where(im == icn)]
            ycn = ym[np.where(im == icn)]
            mcn = m[np.where(im == icn)]

            nc = nc + 1

            for ix in range(len(xcn)):
                print('Filament: ' + str(icn) + ' (' + str(np.unique(im)[-1]) +
                      ') Profile: ' + str(ix + 1) + ' (' + str(len(xcn)) + ')')
                if (ycn[ix] >= pix_edge) and (
                        xcn[ix] >= pix_edge
                ):  # if the point lies inside the confidence area determined by the picture edge to discard
                    if mcn[ix] >= 1e6:  # if the skeleton line is vertical
                        direction = 0
                        x_interp = np.arange(0, self._mat_img.shape[1])
                        y_interp = np.array(
                            [int(x) for x in ycn[ix] * np.ones(len(x_interp))])
                        offset_edge = int(ascale) + int(pix_back)
                    elif np.abs(mcn[ix]) < 1 / self._mat_img.shape[
                            1]:  # if the skeleton line is horizontal
                        direction = 1
                        y_interp = np.arange(0, self._mat_img.shape[0])
                        x_interp = np.array(
                            [int(x) for x in xcn[ix] * np.ones(len(y_interp))])
                        offset_edge = int(ascale) + int(pix_back)
                    else:  # if the skeleton line is diagonal
                        direction = 2
                        x_pline = np.arange(0, self._mat_img.shape[1])
                        y_pline = ycn[ix] + 1 / mcn[ix] * (xcn[ix] - x_pline)

                        if y_pline[1] > y_pline[-1]:
                            if np.max(y_pline) >= self._mat_img.shape[0]:
                                ind_y1 = np.where(y_pline >= self._mat_img.
                                                  shape[0])[0][-1] + 1
                            else:
                                ind_y1 = 1
                            if np.min(y_pline) < 0:
                                ind_y2 = np.where(y_pline < 0)[0][0] - 1
                            else:
                                ind_y2 = len(y_pline)
                        else:
                            if np.max(y_pline) >= self._mat_img.shape[0]:
                                ind_y2 = np.where(y_pline >= self._mat_img.
                                                  shape[0])[0][0] - 1
                            else:
                                ind_y2 = len(y_pline)
                            if np.min(y_pline) < 0:
                                ind_y1 = np.where(y_pline < 0)[0][-1] - 1
                            else:
                                ind_y1 = 1

                        x_profile = [int(x) for x in x_pline[ind_y1:ind_y2]]
                        y_profile = [int(x) for x in y_pline[ind_y1:ind_y2]]

                        try:
                            f_interp = interp1d(x_profile, y_profile)
                            x_interp = np.arange(np.min(x_profile),
                                                 np.max(x_profile),
                                                 step=0.1)
                            offset_edge = 10 * (int(ascale) + int(pix_back))
                            y_interp = f_interp(x_interp)
                        except ValueError:
                            x_interp = x_profile
                            y_interp = y_profile
                            offset_edge = int(ascale) + int(pix_back)

                    x_profile_int = [int(x) for x in x_interp]
                    y_profile_int = [int(x) for x in y_interp]

                    x_profile = np.array(x_profile_int)
                    y_profile = np.array(y_profile_int)

                    try:
                        xms = np.mean(
                            np.where(np.abs(x_profile - xcn[ix]) < 2))
                        yms = np.mean(
                            np.where(np.abs(y_profile - ycn[ix]) < 2))

                        if direction == 0: posx = int(xms)
                        elif direction == 1: posx = int(yms)
                        elif direction == 2: posx = int(np.mean([xms, yms]))
                        sign_position = 0 * x_profile
                        sign_position[:posx] = -1
                        sign_position[posx:] = 1

                        mask_profile = 0 * self._mask_edge
                        mask_profile[y_profile[posx:], x_profile[posx:]] = 1
                        mask_profile[y_profile[:posx], x_profile[:posx]] = -1

                        mask_overlap = mask_profile * binary_dilation(
                            self._mask_edge)

                        try:
                            ymatch = np.where(mask_overlap < 0)[0]
                            xmatch = np.where(mask_overlap < 0)[1]
                            dmatch = np.sqrt((xmatch - xcn[ix])**2 +
                                             (ymatch - ycn[ix])**2)
                            ind_x1 = xmatch[np.argmin(dmatch)]
                            ind_y1 = ymatch[np.argmin(dmatch)]

                            ymatch = np.where(mask_overlap > 0)[0]
                            xmatch = np.where(mask_overlap > 0)[1]
                            dmatch = np.sqrt((xmatch - xcn[ix])**2 +
                                             (ymatch - ycn[ix])**2)
                            ind_x2 = xmatch[np.argmin(dmatch)]
                            ind_y2 = ymatch[np.argmin(dmatch)]
                            ind_xmatch = [ind_x1, ind_x2]
                            ind_ymatch = [ind_y1, ind_y2]

                            try:
                                if direction == 0:
                                    ind_1 = np.where(x_profile == ind_x1)[0][0]
                                    ind_2 = np.where(x_profile == ind_x2)[0][0]
                                else:
                                    ind_1 = np.where(y_profile == ind_y1)[0][0]
                                    ind_2 = np.where(y_profile == ind_y2)[0][0]
                                xmatch = x_profile[ind_1 - offset_edge:ind_2 +
                                                   offset_edge]
                                ymatch = y_profile[ind_1 - offset_edge:ind_2 +
                                                   offset_edge]

                                full_profile.append(
                                    np.array(self._mat_img[y_profile,
                                                           x_profile]))
                                int_profile.append(
                                    np.array(self._mat_img[ymatch, xmatch]))
                                fiber_xc.append(
                                    np.mean(
                                        [x_profile[ind_1], x_profile[ind_2]]))
                                fiber_yc.append(
                                    np.mean(
                                        [y_profile[ind_1], y_profile[ind_2]]))
                                fiber_x1.append(x_profile[ind_1])
                                fiber_x2.append(x_profile[ind_2])
                                fiber_y1.append(y_profile[ind_1])
                                fiber_y2.append(y_profile[ind_2])
                                fiber_e1.append(self._WT_m1[fiber_y1[-1],
                                                            fiber_x1[-1]])
                                fiber_e2.append(self._WT_m1[fiber_y2[-1],
                                                            fiber_x2[-1]])
                                fiber_number.append(nc)
                                fiber_slope.append(mcn[ix])
                                dist_full = np.sqrt(
                                    (x_profile - fiber_xc[-1])**2 +
                                    (y_profile -
                                     fiber_yc[-1])**2) * sign_position
                                full_position.append(dist_full)
                                pos_profile.append(
                                    dist_full[ind_1 - offset_edge:ind_2 +
                                              offset_edge])
                            except IndexError as e:
                                print('error 182:  ' + str(e))
                        except ValueError as e:
                            print('error 183:  ' + str(e))
                    except ValueError as e:
                        print('error 184: ' + str(e))

        mask_newlabel = 0 * self._mat_img
        fx = [int(x) for x in fiber_xc]
        fy = [int(x) for x in fiber_yc]
        mask_newlabel[np.array(fy), np.array(fx)] = 1

        labelled_filaments = remove_small_objects(label(mask_newlabel),
                                                  min_size=3)
        [yl, xl] = np.where(labelled_filaments)
        xy_l = [[xl[ix], yl[ix]] for ix in range(len(xl))]
        new_ind = [0 for x in fiber_xc]
        for ix in range(0, len(fiber_xc)):
            if [fx[ix], fy[ix]] in xy_l: new_ind[ix] = 1

        new_ind = np.array(new_ind)
        ind_del = np.where(new_ind == 0)[0]
        self.progressBar['value'] = icn + 1
        self.progressBar.update()

        self._full_int_profile = np.delete(np.array(full_profile),
                                           ind_del,
                                           axis=0)
        self._full_position = np.delete(np.array(full_position),
                                        ind_del,
                                        axis=0)
        self._int_profile = np.delete(np.array(int_profile), ind_del, axis=0)
        self._fiber_xc = np.delete(np.array(fiber_xc), ind_del, axis=0)
        self._fiber_yc = np.delete(np.array(fiber_yc), ind_del, axis=0)
        self._fiber_x1 = np.delete(np.array(fiber_x1), ind_del, axis=0)
        self._fiber_x2 = np.delete(np.array(fiber_x2), ind_del, axis=0)
        self._fiber_y1 = np.delete(np.array(fiber_y1), ind_del, axis=0)
        self._fiber_y2 = np.delete(np.array(fiber_y2), ind_del, axis=0)
        self._fiber_e1 = np.delete(np.array(fiber_e1), ind_del, axis=0)
        self._fiber_e2 = np.delete(np.array(fiber_e2), ind_del, axis=0)
        self._fiber_number = np.delete(np.array(fiber_number), ind_del, axis=0)
        self._fiber_slope = np.delete(np.array(fiber_slope), ind_del, axis=0)
        self._pos_profile = np.delete(np.array(pos_profile), ind_del, axis=0)

        self.progressBar['value'] = 0
        self.progressBar.update()