Exemple #1
0
    def view(self):
        """Create a matplotlib animated view of the contents.

        """
        cv = CollectionViewer(self.images)
        cv.show()
        return cv
    def view(self):
        """Create a matplotlib animated view of the contents.

        """
        cv = CollectionViewer(self.images)
        cv.show()
        return cv
class CropViewer:
    def __init__(self, search_pattern):
        bottom_px = 60

        self.bottom_px = bottom_px

        plugin = Plugin(image_filter=self.image_filter, dock="right")

        self.setup_names = ['Bottom']

        self.show_orig = CheckBox('show_orig', value=False, alignment='left')

        plugin += self.show_orig
        plugin += ComboBox('setup', self.setup_names)
        plugin += Slider('bottom_px',
                         0,
                         500,
                         value=self.bottom_px,
                         value_type='int')
        plugin += Button("Print", callback=self.on_print_click)

        fnames = [path for path in glob.iglob(search_pattern, recursive=True)]
        images, gray_images = read_images(fnames)

        self.viewer = CollectionViewer(images)
        self.viewer += plugin

    def image_filter(self, image, *args, **kwargs):
        print("image: ", image.shape)

        show_orig = kwargs["show_orig"]
        setup = kwargs["setup"]
        self.bottom_px = kwargs["bottom_px"]

        if show_orig:
            return image

        # crop_img = img[200:400, 100:300]  # Crop from x, y, w, h -> 100, 200, 300, 400
        # NOTE: its img[y: y + h, x: x + w] and *not* img[x: x + w, y: y + h]
        result_image = None
        if setup == "Bottom":
            result_image = apply_crop_bottom(image, bottom_px=self.bottom_px)

        return result_image

    def on_print_click(self, args):
        print("""
        bottom_px = {}
        """.format(self.bottom_px))

    def show(self):
        self.viewer.show()
Exemple #4
0
"""
=====================
CollectionViewer demo
=====================

Demo of CollectionViewer for viewing collections of images. This demo uses
the different layers of the gaussian pyramid as image collection.

You can scroll through images with the slider, or you can interact with the
viewer using your keyboard:

left/right arrows
    Previous/next image in collection.
number keys, 0--9
    0% to 90% of collection. For example, "5" goes to the image in the
    middle (i.e. 50%) of the collection.
home/end keys
    First/last image in collection.

"""
import numpy as np
from skimage import data
from skimage.viewer import CollectionViewer
from skimage.transform import pyramid_gaussian

img = data.lena()
img_collection = tuple(pyramid_gaussian(img))

view = CollectionViewer(img_collection)
view.show()
Exemple #5
0
class ColorViewer:
    def __init__(self, search_pattern):
        self.plugin = Plugin(image_filter=self.image_filter, dock="right")

        self.setup_names = ['Yellow', 'White', 'Yellow / White']
        self.color_spaces = ['LAB', 'HSV', 'HLS', 'LUV']

        self.show_orig = CheckBox('show_orig', value=False, alignment='left')

        self.plugin += self.show_orig
        self.setup = ComboBox('setup', self.setup_names)
        self.color_space = ComboBox('color_space', self.color_spaces)
        self.sensity_range = Slider('sensity_range',
                                    10,
                                    100,
                                    value=sensity_range,
                                    value_type='int')
        self.lower_yellow_1 = Slider('lower_yellow_1',
                                     0,
                                     255,
                                     value=lower_yellow_1,
                                     value_type='int')
        self.lower_yellow_2 = Slider('lower_yellow_2',
                                     0,
                                     255,
                                     value=lower_yellow_2,
                                     value_type='int')
        self.lower_yellow_3 = Slider('lower_yellow_3',
                                     0,
                                     255,
                                     value=lower_yellow_3,
                                     value_type='int')
        self.upper_yellow_1 = Slider('upper_yellow_1',
                                     0,
                                     255,
                                     value=upper_yellow_1,
                                     value_type='int')
        self.upper_yellow_2 = Slider('upper_yellow_2',
                                     0,
                                     255,
                                     value=upper_yellow_2,
                                     value_type='int')
        self.upper_yellow_3 = Slider('upper_yellow_3',
                                     0,
                                     255,
                                     value=upper_yellow_3,
                                     value_type='int')

        self.lower_white_1 = Slider('lower_white_1',
                                    0,
                                    255,
                                    value=lower_white_1,
                                    value_type='int')
        self.lower_white_2 = Slider('lower_white_2',
                                    0,
                                    255,
                                    value=lower_white_2,
                                    value_type='int')
        self.lower_white_3 = Slider('lower_white_3',
                                    0,
                                    255,
                                    value=lower_white_3,
                                    value_type='int')
        self.upper_white_1 = Slider('upper_white_1',
                                    0,
                                    255,
                                    value=upper_white_1,
                                    value_type='int')
        self.upper_white_2 = Slider('upper_white_2',
                                    0,
                                    255,
                                    value=upper_white_2,
                                    value_type='int')
        self.upper_white_3 = Slider('upper_white_3',
                                    0,
                                    255,
                                    value=upper_white_3,
                                    value_type='int')

        self.plugin += self.setup
        self.plugin += self.color_space
        # self.plugin += self.sensity_range
        self.plugin += self.lower_yellow_1
        self.plugin += self.lower_yellow_2
        self.plugin += self.lower_yellow_3
        self.plugin += self.upper_yellow_1
        self.plugin += self.upper_yellow_2
        self.plugin += self.upper_yellow_3

        self.plugin += self.lower_white_1
        self.plugin += self.lower_white_2
        self.plugin += self.lower_white_3
        self.plugin += self.upper_white_1
        self.plugin += self.upper_white_2
        self.plugin += self.upper_white_3

        fnames = [path for path in glob.iglob(search_pattern, recursive=True)]
        images, gray_images = read_images(fnames)

        self.viewer = CollectionViewer(images)
        self.viewer.connect_event('button_press_event', self.on_filter_color)
        self.viewer.connect_event('key_press_event', self.on_press)
        self.viewer += self.plugin

    def on_filter_color(self, event):
        if event.inaxes and event.inaxes.get_navigate():
            self.viewer.status_message(
                self.format_coord(event.xdata, event.ydata))
        else:
            self.viewer.status_message('')

    def format_coord(self, x, y):
        x = int(x + 0.5)
        y = int(y + 0.5)
        pixel = self.viewer.image[y, x]

        lower_lst = [
            pixel[0] - self.sensity_range.val,
            pixel[1] - self.sensity_range.val,
            pixel[2] - self.sensity_range.val
        ]
        upper_lst = [
            pixel[0] + self.sensity_range.val,
            pixel[1] + self.sensity_range.val,
            pixel[2] + self.sensity_range.val
        ]

        setup = self.setup.val
        if setup == "Yellow":
            self.update_yellow_params(*lower_lst, *upper_lst)
        elif setup == "White":
            self.update_white_params(*lower_lst, *upper_lst)
        else:
            print("Select only one color!")

    def update_yellow_params(self, lower1, lower2, lower3, upper1, upper2,
                             upper3):
        lower1 = self.update_val(self.lower_yellow_1, lower1)
        lower2 = self.update_val(self.lower_yellow_2, lower2)
        lower3 = self.update_val(self.lower_yellow_3, lower3)
        upper1 = self.update_val(self.upper_yellow_1, upper1)
        upper2 = self.update_val(self.upper_yellow_2, upper2)
        upper3 = self.update_val(self.upper_yellow_3, upper3)
        self.plugin.filter_image()

    def update_white_params(self, lower1, lower2, lower3, upper1, upper2,
                            upper3):
        lower1 = self.update_val(self.lower_white_1, lower1)
        lower2 = self.update_val(self.lower_white_2, lower2)
        lower3 = self.update_val(self.lower_white_3, lower3)
        upper1 = self.update_val(self.upper_white_1, upper1)
        upper2 = self.update_val(self.upper_white_2, upper2)
        upper3 = self.update_val(self.upper_white_3, upper3)
        self.plugin.filter_image()

    def image_filter(self, image, *args, **kwargs):
        print("image: ", image.shape)

        image = apply_crop_bottom(image)
        # print("cropped image: ", image.shape)

        image, M, Minv = apply_warp(image)
        # print("warped image: ", image.shape)

        show_orig = kwargs["show_orig"]
        setup = kwargs["setup"]
        color_space = kwargs["color_space"]
        lower_yellow_1 = kwargs["lower_yellow_1"]
        lower_yellow_2 = kwargs["lower_yellow_2"]
        lower_yellow_3 = kwargs["lower_yellow_3"]
        upper_yellow_1 = kwargs["upper_yellow_1"]
        upper_yellow_2 = kwargs["upper_yellow_2"]
        upper_yellow_3 = kwargs["upper_yellow_3"]

        lower_white_1 = kwargs["lower_white_1"]
        lower_white_2 = kwargs["lower_white_2"]
        lower_white_3 = kwargs["lower_white_3"]
        upper_white_1 = kwargs["upper_white_1"]
        upper_white_2 = kwargs["upper_white_2"]
        upper_white_3 = kwargs["upper_white_3"]

        if show_orig:
            return image

        lower_yellow = np.array(
            [lower_yellow_1, lower_yellow_2, lower_yellow_3])
        upper_yellow = np.array(
            [upper_yellow_1, upper_yellow_2, upper_yellow_3])

        lower_white = np.array([lower_white_1, lower_white_2, lower_white_3])
        upper_white = np.array([upper_white_1, upper_white_2, upper_white_3])

        target_color_space = cv2.COLOR_RGB2HSV
        if color_space == "LAB":
            target_color_space = cv2.COLOR_RGB2Lab
        elif color_space == "HLS":
            target_color_space = cv2.COLOR_RGB2HLS
        elif color_space == "LUV":
            target_color_space = cv2.COLOR_RGB2LUV

        result_image = None
        if setup == "Yellow":
            result_image = filter_color(image,
                                        lower_yellow,
                                        upper_yellow,
                                        trg_color_space=target_color_space)
        elif setup == "White":
            result_image = filter_color(image,
                                        lower_white,
                                        upper_white,
                                        trg_color_space=target_color_space)
        elif setup == "Yellow / White":
            result_yellow = filter_color(image,
                                         lower_yellow,
                                         upper_yellow,
                                         trg_color_space=target_color_space)
            result_white = filter_color(image,
                                        lower_white,
                                        upper_white,
                                        trg_color_space=target_color_space)
            result_image = cv2.bitwise_or(result_yellow, result_white)

        return result_image

    def on_press(self, event):
        if event.key == 'ctrl+r':
            self.on_reset()
        elif event.key == 'ctrl+p':
            self.on_print()

    def on_print(self, args=None):
        print("""
        lower_yellow_1 = {}
        lower_yellow_2 = {}
        lower_yellow_3 = {}
        upper_yellow_1 = {}
        upper_yellow_2 = {}
        upper_yellow_3 = {}

        lower_white_1 = {}
        lower_white_2 = {}
        lower_white_3 = {}
        upper_white_1 = {}
        upper_white_2 = {}
        upper_white_3 = {}
                    """.format(
            self.lower_yellow_1.val, self.lower_yellow_2.val,
            self.lower_yellow_3.val, self.upper_yellow_1.val,
            self.upper_yellow_2.val, self.upper_yellow_3.val,
            self.lower_white_1.val, self.lower_white_2.val,
            self.lower_white_3.val, self.upper_white_1.val,
            self.upper_white_2.val, self.upper_white_3.val))

    def on_reset(self, args=None):
        self.update_val(self.lower_yellow_1, lower_yellow_1)
        self.update_val(self.lower_yellow_2, lower_yellow_2)
        self.update_val(self.lower_yellow_3, lower_yellow_3)
        self.update_val(self.upper_yellow_1, upper_yellow_1)
        self.update_val(self.upper_yellow_2, upper_yellow_2)
        self.update_val(self.upper_yellow_3, upper_yellow_3)

        self.update_val(self.lower_white_1, lower_white_1)
        self.update_val(self.lower_white_2, lower_white_2)
        self.update_val(self.lower_white_3, lower_white_3)
        self.update_val(self.upper_white_1, upper_white_1)
        self.update_val(self.upper_white_2, upper_white_2)
        self.update_val(self.upper_white_3, upper_white_3)

        self.plugin.filter_image()

    def update_val(self, comp, newval, min_val=0, max_val=255):
        newval = max(0, newval)
        newval = min(255, newval)

        comp.val = newval
        comp.editbox.setText("%s" % newval)

        return newval

    def show(self):
        self.viewer.show()
"""
=====================
CollectionViewer demo
=====================

Demo of CollectionViewer for viewing collections of images. This demo uses
the different layers of the gaussian pyramid as image collection.

You can scroll through images with the slider, or you can interact with the
viewer using your keyboard:

left/right arrows
    Previous/next image in collection.
number keys, 0--9
    0% to 90% of collection. For example, "5" goes to the image in the
    middle (i.e. 50%) of the collection.
home/end keys
    First/last image in collection.

"""
from skimage import data
from skimage.viewer import CollectionViewer
from skimage.transform import pyramid_gaussian


img = data.astronaut()
img_collection = tuple(pyramid_gaussian(img))

view = CollectionViewer(img_collection)
view.show()
Exemple #7
0
class RoiViewer:
    def __init__(self, search_pattern):
        blur_kernel_size = 1

        cal_fnames = [
            path for path in glob.iglob('camera_cal/*.jpg', recursive=True)
        ]
        cal_images, cal_gray_images = read_images(cal_fnames)
        self.objpoints, self.imgpoints, _ = get_chessboard_corners(
            cal_images, cal_gray_images)

        self.blur_kernel_size = blur_kernel_size
        self.top_left_x = top_left_x
        self.top_left_y = top_left_y
        self.top_right_x = top_right_x
        self.top_right_y = top_right_y
        self.bottom_right_x = bottom_right_x
        self.bottom_right_y = bottom_right_y
        self.bottom_left_x = bottom_left_x
        self.bottom_left_y = bottom_left_y

        plugin = Plugin(image_filter=self.image_filter, dock="right")

        self.setup_names = [
            'ROI poly', "ROI Transformation", 'ROI Transformed',
            "Final Transformation poly", 'Final Transformation',
            'Final Transformed'
        ]

        self.show_orig = CheckBox('show_orig', value=False, alignment='left')

        plugin += self.show_orig
        plugin += ComboBox('setup', self.setup_names)
        plugin += Slider('blur_kernel_size',
                         0,
                         31,
                         value=self.blur_kernel_size,
                         value_type='int')
        plugin += Slider('top_left_x', 0, 1, value=self.top_left_x)
        plugin += Slider('top_left_y', 0, 1, value=self.top_left_y)
        plugin += Slider('top_right_x', 0, 1, value=self.top_right_x)
        plugin += Slider('top_right_y', 0, 1, value=self.top_right_y)
        plugin += Slider('bottom_right_x', 0, 1, value=self.bottom_right_x)
        plugin += Slider('bottom_right_y', 0, 1, value=self.bottom_right_y)
        plugin += Slider('bottom_left_x', 0, 1, value=self.bottom_left_x)
        plugin += Slider('bottom_left_y', 0, 1, value=self.bottom_left_y)
        plugin += Button("Print", callback=self.on_print_click)

        fnames = [path for path in glob.iglob(search_pattern, recursive=True)]
        images, gray_images = read_images(fnames)

        self.viewer = CollectionViewer(images)
        self.viewer += plugin

    def image_filter(self, image, *args, **kwargs):
        print("image: ", image.shape)

        image = correct_distortion(image, self.objpoints, self.imgpoints)
        print("undistorted image: ", image.shape)

        image = apply_crop_bottom(image)
        print("cropped image: ", image.shape)

        show_orig = kwargs["show_orig"]
        setup = kwargs["setup"]
        self.blur_kernel_size = kwargs["blur_kernel_size"]
        self.top_left_x = kwargs["top_left_x"]
        self.top_left_y = kwargs["top_left_y"]
        self.top_right_x = kwargs["top_right_x"]
        self.top_right_y = kwargs["top_right_y"]
        self.bottom_right_x = kwargs["bottom_right_x"]
        self.bottom_right_y = kwargs["bottom_right_y"]
        self.bottom_left_x = kwargs["bottom_left_x"]
        self.bottom_left_y = kwargs["bottom_left_y"]

        if show_orig:
            return image

        height, width = image.shape[:2]
        src_top_left = (width * self.top_left_x, height * self.top_left_y)
        src_top_right = (width * self.top_right_x, height * self.top_right_y)
        src_bottom_right = (width * self.bottom_right_x,
                            height * self.bottom_right_y)
        src_bottom_left = (width * self.bottom_left_x,
                           height * self.bottom_left_y)

        trg_top_left = (width * self.bottom_left_x, 0)
        trg_top_right = (width * self.bottom_right_x, 0)
        trg_bottom_right = (width * self.bottom_right_x,
                            height * self.bottom_right_y)
        trg_bottom_left = (width * self.bottom_left_x,
                           height * self.bottom_left_y)

        result_image = image
        if setup == "ROI poly":
            vertices = np.array([[
                src_top_left, src_top_right, src_bottom_right, src_bottom_left
            ]],
                                dtype=np.int32)
            cv2.polylines(result_image, [vertices],
                          isClosed=True,
                          color=(0, 255, 255),
                          thickness=2)
        elif setup == "ROI Transformation":
            vertices = np.array([[
                trg_top_left, trg_top_right, trg_bottom_right, trg_bottom_left
            ]],
                                dtype=np.int32)
            cv2.polylines(result_image, [vertices],
                          isClosed=True,
                          color=(0, 255, 255),
                          thickness=2)
        elif setup == "ROI Transformed":
            src = np.float32([
                src_top_left, src_top_right, src_bottom_right, src_bottom_left
            ])
            trg = np.float32([
                trg_top_left, trg_top_right, trg_bottom_right, trg_bottom_left
            ])
            result_image, M, Minv = warp_image(result_image, src, trg)
        elif setup == "Final Transformation poly":
            result_image = apply_color_and_threshold(image) * 255
            vertices = np.array([[
                src_top_left, src_top_right, src_bottom_right, src_bottom_left
            ]],
                                dtype=np.int32)
            cv2.polylines(result_image, [vertices],
                          isClosed=True,
                          color=(255, 255, 255),
                          thickness=2)
        elif setup == "Final Transformation":
            result_image = apply_color_and_threshold(image) * 255
            vertices = np.array([[
                trg_top_left, trg_top_right, trg_bottom_right, trg_bottom_left
            ]],
                                dtype=np.int32)
            cv2.polylines(result_image, [vertices],
                          isClosed=True,
                          color=(255, 255, 255),
                          thickness=2)
        elif setup == "Final Transformed":
            src = np.float32([
                src_top_left, src_top_right, src_bottom_right, src_bottom_left
            ])
            trg = np.float32([
                trg_top_left, trg_top_right, trg_bottom_right, trg_bottom_left
            ])
            result_image, M, Minv = warp_image(image, src, trg)
            result_image = apply_color_and_threshold(result_image) * 255

        return result_image

    def on_print_click(self, args):
        print("""
        blur_kernel_size = {}
        top_left_x = {}
        top_left_y = {}
        top_right_x = {}
        top_right_y = {}
        bottom_right_x = {}
        bottom_right_y = {}
        bottom_left_x = {}
        bottom_left_y = {}
        """.format(self.blur_kernel_size, self.top_left_x, self.top_left_y,
                   self.top_right_x, self.top_right_y, self.bottom_right_x,
                   self.bottom_right_y, self.bottom_left_x,
                   self.bottom_left_y))

    def show(self):
        self.viewer.show()
 def show(self):
     """Show the stack of images in a skimage CollectionViewer window"""
     #stackims=[self[i] for i in range(len(self))]
     cv=CollectionViewer(self)
     cv.show()
     return cv  
Exemple #9
0
    return util.img_as_ubyte(io.imread(f), force_copy=True)


slice_collection = io.ImageCollection(path.join(SLICE_DIR, SLICE_PATTERN),
                                      load_func=load_uint8)

vol_img = slice_collection.concatenate()

img_otsu = otsu(vol_img)
save_samples('otsu_mask_initial', red_overlay(vol_img, img_otsu))
save_samples('otsu_initial', img_otsu)

# img_sobel = slice_by_slice(sobel_edges, vol_img, datatype=np.float)
# img_binary = img_sobel > EDGE_THRESHOLD
# save_samples('sobel', img_sobel)
# save_samples('sobel_binary', img_binary)
# save_samples('sobel_overlay', red_overlay(vol_img, img_binary))

img_binary = slice_by_slice(fill_interior, img_otsu)
save_samples('filled', red_overlay(vol_img, img_binary))

img_binary = slice_by_slice(erode_to_infill, img_binary)
save_samples('eroded', red_overlay(vol_img, img_binary))

img_binary[28:84, :, :] = 0
percentage = 100 * np.sum(img_otsu & img_binary) / np.sum(img_binary)
print('Infill percentage: {0} %'.format(percentage))

viewer = CollectionViewer(red_overlay(vol_img, img_binary))
viewer.show()
class ThreshViewer:
    def __init__(self, search_pattern):
        plugin = Plugin(image_filter=self.image_filter, dock="right")

        self.setup_names = [
            'Sobel Thresh X', 'Sobel Thresh Y', 'Sobel Thresh X / Y',
            'Magnitude Thresh', 'Gradient Direction',
            'Magnitude / Gradient Direction Thresh', "2 & 2", "2 | 2"
        ]

        self.show_orig = CheckBox('show_orig', value=False, alignment='left')

        plugin += self.show_orig
        plugin += ComboBox('setup', self.setup_names)
        plugin += Slider('grad_ksize',
                         0,
                         31,
                         value=grad_ksize,
                         value_type='int')
        plugin += Slider('grad_thresh_low',
                         0,
                         255,
                         value=grad_thresh_low,
                         value_type='int')
        plugin += Slider('grad_thresh_high',
                         0,
                         255,
                         value=grad_thresh_high,
                         value_type='int')
        plugin += Slider('mag_binary_ksize',
                         0,
                         31,
                         value=mag_binary_ksize,
                         value_type='int')
        plugin += Slider('mag_binary_thresh_low',
                         0,
                         255,
                         value=mag_binary_thresh_low,
                         value_type='int')
        plugin += Slider('mag_binary_thresh_high',
                         0,
                         255,
                         value=mag_binary_thresh_high,
                         value_type='int')
        plugin += Slider('dir_binary_ksize',
                         0,
                         31,
                         value=dir_binary_ksize,
                         value_type='int')
        plugin += Slider('dir_binary_thresh_low',
                         0,
                         np.pi,
                         value=dir_binary_thresh_low)
        plugin += Slider('dir_binary_thresh_high',
                         0,
                         np.pi,
                         value=dir_binary_thresh_high)

        fnames = [path for path in glob.iglob(search_pattern, recursive=True)]
        images, gray_images = read_images(fnames)

        self.viewer = CollectionViewer(images)
        self.viewer += plugin

    def image_filter(self, image, *args, **kwargs):
        print("image: ", image.shape)

        image = apply_crop_bottom(image)
        print("cropped image: ", image.shape)

        image, M, Minv = apply_warp(image)
        print("warped image: ", image.shape)

        show_orig = kwargs["show_orig"]
        setup = kwargs["setup"]
        grad_ksize = kwargs["grad_ksize"]
        grad_thresh_low = kwargs["grad_thresh_low"]
        grad_thresh_high = kwargs["grad_thresh_high"]
        mag_binary_ksize = kwargs["mag_binary_ksize"]
        mag_binary_thresh_low = kwargs["mag_binary_thresh_low"]
        mag_binary_thresh_high = kwargs["mag_binary_thresh_high"]
        dir_binary_ksize = kwargs["dir_binary_ksize"]
        dir_binary_thresh_low = kwargs["dir_binary_thresh_low"]
        dir_binary_thresh_high = kwargs["dir_binary_thresh_high"]

        if show_orig:
            # return apply_color_and_threshold(image) * 255
            return image

        gradx = abs_sobel_thresh(image,
                                 orient='x',
                                 sobel_kernel=grad_ksize,
                                 thresh=(grad_thresh_low, grad_thresh_high),
                                 rgb2gray=False)
        grady = abs_sobel_thresh(image,
                                 orient='y',
                                 sobel_kernel=grad_ksize,
                                 thresh=(grad_thresh_low, grad_thresh_high),
                                 rgb2gray=False)

        mag_binary = mag_thresh(image,
                                sobel_kernel=mag_binary_ksize,
                                thresh=(mag_binary_thresh_low,
                                        mag_binary_thresh_high),
                                rgb2gray=False)
        dir_binary = dir_threshold(image,
                                   sobel_kernel=dir_binary_ksize,
                                   thresh=(dir_binary_thresh_low,
                                           dir_binary_thresh_high),
                                   rgb2gray=False)

        combined_sobel = np.zeros_like(gradx)
        combined_sobel[((gradx == 1) & (grady == 1))] = 1

        combined_magn_grad = np.zeros_like(mag_binary)
        combined_magn_grad[((mag_binary == 1) & (dir_binary == 1))] = 1

        result_image = None
        if setup == "Sobel Thresh X":
            result_image = gradx
        elif setup == "Sobel Thresh Y":
            result_image = grady
        elif setup == "Sobel Thresh X / Y":
            result_image = combined_sobel
        elif setup == "Magnitude Thresh":
            result_image = mag_binary
        elif setup == "Gradient Direction":
            result_image = dir_binary
        elif setup == "Magnitude / Gradient Direction Thresh":
            result_image = combined_magn_grad
        elif setup == "2 & 2":
            result_image = np.zeros_like(combined_sobel)
            result_image[((combined_sobel == 1) &
                          (combined_magn_grad == 1))] = 1
        elif setup == "2 | 2":
            result_image = np.zeros_like(combined_sobel)
            result_image[((combined_sobel == 1) |
                          (combined_magn_grad == 1))] = 1

        return result_image

    def show(self):
        self.viewer.show()
from skimage import morphology
from scipy import ndimage as ndi
from skimage.viewer import ImageViewer
from skimage.viewer import CollectionViewer
import numpy as np

im3d = np.random.rand(100, 100, 100)

viewer3d = CollectionViewer(im3d)
viewer3d.show()
==================================

Demo of a CollectionViewer for viewing collections of images with the
`autolevel` rank filter connected as a plugin.

"""
from skimage import data
from skimage.filter import rank
from skimage.morphology import disk

from skimage.viewer import CollectionViewer
from skimage.viewer.widgets import Slider
from skimage.viewer.plugins.base import Plugin


# Wrap autolevel function to make the disk size a filter argument.
def autolevel(image, disk_size):
    return rank.autolevel(image, disk(disk_size))


img_collection = [data.camera(), data.coins(), data.text()]

plugin = Plugin(image_filter=autolevel)
plugin += Slider("disk_size", 2, 8, value_type="int")
plugin.name = "Autolevel"

viewer = CollectionViewer(img_collection)
viewer += plugin

viewer.show()
Exemple #13
0
#!/usr/bin/env python

import numpy as np
import skimage.io as io
from skimage.viewer import CollectionViewer

import cremi.evaluation as evaluation
import cremi.io.CremiFile as CremiFile


if __name__ == "__main__":
    img = [io.imread('example.png')]
    
    for w in (0, 2, 4, 10):
        target = np.copy(img[0])[...,np.newaxis]
        evaluation.create_border_mask(img[0][...,np.newaxis],target,w,105,axis=2)
        img.append(target[...,0])

    v = CollectionViewer(img)
    v.show()

    cfIn  = CremiFile('example.h5', 'r')
    cfOut = CremiFile('output.h5', 'a')

    evaluation.create_and_write_masked_neuron_ids(cfIn, cfOut, 3, 240, overwrite=True)
Exemple #14
0
def show_image_collection(im3d):
    viewer3d = CollectionViewer(im3d)
    viewer3d.show()
Exemple #15
0
folder = r'..\tests\coretestdata\hysteresis_test'
editfolder = r'..\tests\coretestdata\hysteresis_test\edited_ims'

os.chdir(folder)
background = KerrArray('image0000_background.png')
background = background.convert_float()
print 'loading images...'
kl = KerrList('image000*unproccessed.png',
              conserve_memory=False,
              get_metadata=False)
list(kl)  #make sure all images loaded
print 'images loaded'

#%%

print 'convert float'
kl.apply_all('convert_float')  #convert pixels to decimal values
print 'correct_drift'
kl.apply_all('correct_drift', ref=background, upsample_factor=200)
print 'subtract'
for i, im in enumerate(kl):
    kl[i] = 16 * (kl[i] - background) + 0.5
    kl[i] = kl[i].clip_intensity()
    #skimage.io.imsave(os.path.join(savefolder,kl.files[i]),kl[i])

print np.array(kl.slice_metadata(key='correct_drift', values_only=True))

cv = CollectionViewer(kl)
cv.show()