Beispiel #1
0
def tophat_test(plot=True):

    arr = np.ones((100, 100), dtype="float64")

    yy, xx = np.mgrid[-50:50, -50:50]

    arr[xx**2 + yy**2 <= 30**2] = 0.0

    struct = disk(32).astype("uint8")

    bth_nd = nd.black_tophat(arr, structure=struct)

    bth_cv = cv2.morphologyEx(arr, cv2.MORPH_BLACKHAT, struct)

    if plot:
        import matplotlib.pyplot as p
        p.subplot(131)
        p.imshow(bth_nd)
        p.colorbar()
        p.subplot(132)
        p.imshow(bth_cv)
        p.colorbar()
        p.subplot(133)
        p.imshow(np.abs(bth_nd - bth_cv))
        p.colorbar()
        p.show()

    np.testing.assert_equal(bth_nd, bth_cv)
Beispiel #2
0
def watersplit(_probs, _points, img_pil, blob_ind):
    import numpy as np
    from skimage.morphology import watershed
    from skimage.segmentation import find_boundaries
    from scipy import ndimage
    from scipy import ndimage as ndi

    points = _points.copy()
    img_pilb = img_pil.convert('L')

    # points[points!=0] = np.arange(1, points.sum()+1)
    points = ndi.label(points)[0]
    points = points.astype(float)

    # probs = ndimage.black_tophat(_probs.copy(), 7)
    probs = ndimage.black_tophat(_probs.clone(), 7)
    # seg =  watershed(probs, points, mask=img_pilb)
    water_mask =  watershed(probs, points, mask=blob_ind)
    mask_list = []
    for p in np.unique(points):
        if p == 0:
            continue 
        y_list, x_list = np.where(points==p)
        mask_list += [{'yi':y_list[0], 'xi':x_list[0], 'mask':water_mask==p}]
    
    # for i, mask_dict in enumerate(mask_list):
    #     img_maskspil = hi.mask_on_image(img_pil, mask_dict['mask'])
    #     img_points = hi.points_on_image([mask_dict['yi']], [mask_dict['xi']], img_maskspil)
    #     hu.save_image('water_mask_%d.jpg' % i, img_points)
    return mask_list
def tophat_test(plot=True):

    arr = np.ones((100, 100), dtype="float64")

    yy, xx = np.mgrid[-50:50, -50:50]

    arr[xx**2 + yy**2 <= 30**2] = 0.0

    struct = disk(32).astype("uint8")

    bth_nd = nd.black_tophat(arr, structure=struct)

    bth_cv = cv2.morphologyEx(arr, cv2.MORPH_BLACKHAT, struct)

    if plot:
        import matplotlib.pyplot as p
        p.subplot(131)
        p.imshow(bth_nd)
        p.colorbar()
        p.subplot(132)
        p.imshow(bth_cv)
        p.colorbar()
        p.subplot(133)
        p.imshow(np.abs(bth_nd-bth_cv))
        p.colorbar()
        p.show()

    np.testing.assert_equal(bth_nd, bth_cv)
Beispiel #4
0
 def seperate_lungs(self, image):
     segemented_array = np.zeros(image.shape)
     marker_internal, marker_external, marker_watershed = self.generate_marker(
         image)
     # value of gradient (slope) in X and Y-direction
     sobel_filtered_dx = ndimage.sobel(
         image, 1)  # vertical derivate ( detects horizontal edges)
     sobel_filtered_dy = ndimage.sobel(
         image, 0)  # horizontal derivate (detects vertical edges)
     sobel_gradient = np.hypot(
         sobel_filtered_dx, sobel_filtered_dy
     )  # magnitude of gradient, gets rids of a (-)ve sign
     sobel_gradient *= 255.0 / np.max(
         sobel_gradient
     )  # normalize (This is our landscape image and we will fit it with water)
     watershed = morphology.watershed(sobel_gradient, marker_watershed)
     outline = ndimage.morphological_gradient(watershed, size=(3, 3))
     outline = outline.astype(bool)
     # Creation of the disk-kernel
     blackhat_struct = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0],
                        [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
                        [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0],
                        [0, 0, 1, 1, 1, 0, 0]]
     blackhat_struct = ndimage.iterate_structure(blackhat_struct, 7)
     outline += ndimage.black_tophat(outline, structure=blackhat_struct)
     lungfilter = np.bitwise_or(marker_internal, outline)
     lungfilter = ndimage.morphology.binary_closing(lungfilter,
                                                    structure=np.ones(
                                                        (5, 5)),
                                                    iterations=3)
     segmented = np.where(lungfilter == 1, image, -2000 * np.ones(
         (512, 512)))
     segemented_array = segmented
     return segmented
Beispiel #5
0
def seperate_skull(image):

    marker_internal, marker_external, marker_watershed = generate_markers(
        image)

    sobel_filtered_dx = ndimage.sobel(image, 1)
    sobel_filtered_dy = ndimage.sobel(image, 0)
    sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
    sobel_gradient *= 255.0 / np.max(sobel_gradient)

    watershed = morphology.watershed(sobel_gradient, marker_watershed)

    outline = ndimage.morphological_gradient(watershed, size=(3, 3))
    outline = outline.astype(bool)

    blackhat_struct = [[0, 0, 1, 1, 1, 0, 0],
                       [0, 1, 1, 1, 1, 1, 0],
                       [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1],
                       [0, 1, 1, 1, 1, 1, 0],
                       [0, 0, 1, 1, 1, 0, 0]]
    blackhat_struct = ndimage.iterate_structure(blackhat_struct, 8)
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)
    lungfilter = np.bitwise_or(marker_internal, outline)

    lungfilter = ndimage.morphology.binary_closing(
        lungfilter, structure=np.ones((5, 5)), iterations=3)
    segmented = np.where(lungfilter == 1, image, -2000 * np.ones((512, 512)))

    return segmented
Beispiel #6
0
def tophat(img, params):
    if params['footprint_shape'] == 'rectangle':
        footprint = np.ones(
            (params['footprint_size_y'], params['footprint_size_x']),
            dtype=int)
    elif params['footprint_shape'] == 'ellipse':
        a = params['footprint_size_x'] / 2
        b = params['footprint_size_y'] / 2
        x, y = np.mgrid[-ceil(a):ceil(a) + 1, -ceil(b):ceil(b) + 1]
        footprint = ((x / a)**2 + (y / b)**2 < 1) * 1

    mode = params['mode']
    cval = params['cval']
    origin = params['origin']

    if params['type'] == 'black':
        return ndimage.black_tophat(img,
                                    size=None,
                                    footprint=footprint,
                                    structure=None,
                                    mode=mode,
                                    cval=cval,
                                    origin=origin)
    elif params['type'] == 'white':
        return ndimage.white_tophat(img,
                                    size=None,
                                    footprint=footprint,
                                    structure=None,
                                    mode=mode,
                                    cval=cval,
                                    origin=origin)
 def test_black_tophat_operation_sparse_input_struct_zeros(self):
     struct = np.zeros((3, 3, 3))
     print("\n test_black_tophat_operation_sparse_input_struct_zeros...")
     v_output = vc.black_tophat(input_svar,
                                structure=struct,
                                make_float32=False)
     d_output = ndimage.black_tophat(input_svar, structure=struct)
     msgs = "test_black_tophat_operation_sparse_input_struct_zeros"
     self.assertTrue((d_output == v_output).all(), msg=msgs)
Beispiel #8
0
def test_3d_fallback_black_tophat():
    image = np.ones((7, 7, 7), dtype=bool)
    image[2, 2:4, 2:4] = 0
    image[3, 2:5, 2:5] = 0
    image[4, 3:5, 3:5] = 0
    new_image = grey.black_tophat(image)
    footprint = ndimage.generate_binary_structure(3,1)
    image_expected = ndimage.black_tophat(image,footprint=footprint)
    testing.assert_array_equal(new_image, image_expected)
def watersplit(_probs, _points):
    points = _points.copy()

    points[points != 0] = np.arange(1, points.sum() + 1)
    points = points.astype(float)

    probs = ndimage.black_tophat(_probs.copy(), 7)
    seg = watershed(probs, points)

    return find_boundaries(seg)
def get_filtered_lung(image):
    # Creation of the internal Marker
    marker_internal = image < -500
    marker_internal = segmentation.clear_border(marker_internal)
    marker_internal_labels = measure.label(marker_internal)
    areas = [r.area for r in measure.regionprops(marker_internal_labels)]
    areas.sort()
    if len(areas) > 2:
        for region in measure.regionprops(marker_internal_labels):
            if region.area < areas[-2]:
                for coordinates in region.coords:
                    marker_internal_labels[coordinates[0], coordinates[1]] = 0
    marker_internal = marker_internal_labels > 0

    # Creation of the external Marker
    external_a = ndimage.binary_dilation(marker_internal, iterations=10)
    external_b = ndimage.binary_dilation(marker_internal, iterations=55)
    marker_external = external_b ^ external_a
    # Creation of the Watershed Marker matrix
    marker_watershed = np.zeros((512, 512), dtype=np.int)
    marker_watershed += marker_internal * 255
    marker_watershed += marker_external * 128

    # Creation of the Sobel-Gradient
    sobel_filtered_dx = ndimage.sobel(image, 1)
    sobel_filtered_dy = ndimage.sobel(image, 0)
    sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
    sobel_gradient *= 255.0 / np.max(sobel_gradient)

    # Watershed algorithm
    watershed = morphology.watershed(sobel_gradient, marker_watershed)

    # Reducing the image created by the Watershed algorithm to its outline
    outline = ndimage.morphological_gradient(watershed, size=(3, 3))
    outline = outline.astype(bool)

    # Performing Black-Tophat Morphology for reinclusion
    # Creation of the disk-kernel and increasing its size a bit
    blackhat_struct = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0],
                       [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0],
                       [0, 0, 1, 1, 1, 0, 0]]
    blackhat_struct = ndimage.iterate_structure(blackhat_struct, 8)
    # Perform the Black-Hat
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)

    # Use the internal marker and the Outline that was just created to generate the lungfilter
    lungfilter = np.bitwise_or(marker_internal, outline)
    # Close holes in the lungfilter
    # fill_holes is not used here, since in some slices the heart would be reincluded by accident
    lungfilter = ndimage.morphology.binary_closing(lungfilter,
                                                   structure=np.ones((5, 5)),
                                                   iterations=3)

    return lungfilter
 def test_black_tophat_operation_sparse_input_default_value(self):
     print("\n test_black_tophat_operation_sparse_input_default_value...")
     v_output = vc.black_tophat(input_svar,
                                structure=structure,
                                make_float32=False)
     d_output = ndimage.black_tophat(
         input_svar,
         structure=structure,
     )
     msgs = "test_black_tophat_operation_sparse_input_default_value"
     self.assertTrue((d_output == v_output).all(), msg=msgs)
	def __test_black_tophat_operation(self,input_var):		
		print("\n black_tophat Voxel testing...")
		start_time = t.time()
		v_output = vc.black_tophat(input_var,structure=structure,no_of_blocks=PL[0],fakeghost=PL[1],make_float32=False)
		print("black_tophat Voxel testing time taken: ",(t.time() - start_time)," sec")
		#print("\n black_tophat Default testing...")
		start_time = t.time()
		d_output = ndimage.black_tophat(input_var,structure=structure)
		print("black_tophat Default testing time taken: ",(t.time() - start_time)," sec")		
		msgs = "black_tophat_operation_FAIL_with parameters: ",PL
		self.assertTrue((d_output==v_output).all(), msg=msgs)
 def test_black_tophat_operation_sparse_input_blocks_ten(self):
     print("\n test_black_tophat_operation_sparse_input_blocks_ten...")
     v_output = vc.black_tophat(input_svar,
                                structure=structure,
                                no_of_blocks=10,
                                make_float32=False)
     d_output = ndimage.black_tophat(
         input_svar,
         structure=structure,
     )
     msgs = "test_black_tophat_operation_sparse_input_blocks_ten"
     self.assertTrue((d_output == v_output).all(), msg=msgs)
Beispiel #14
0
def test_3d_fallback_black_tophat():
    image = np.ones((7, 7, 7), dtype=bool)
    image[2, 2:4, 2:4] = 0
    image[3, 2:5, 2:5] = 0
    image[4, 3:5, 3:5] = 0

    with expected_warnings(['operator.*deprecated|\A\Z']):
        new_image = grey.black_tophat(image)
    footprint = ndi.generate_binary_structure(3,1)
    with expected_warnings(['operator.*deprecated|\A\Z']):
        image_expected = ndi.black_tophat(image,footprint=footprint)
    testing.assert_array_equal(new_image, image_expected)
 def test_black_tophat_operation_dense_input_fakeghost_four(self):
     print("\n test_black_tophat_operation_dense_input_fakeghost_four...")
     v_output = vc.black_tophat(input_dvar,
                                structure=structure,
                                fakeghost=4,
                                make_float32=False)
     d_output = ndimage.black_tophat(
         input_dvar,
         structure=structure,
     )
     msgs = "test_black_tophat_operation_dense_input_fakeghost_four"
     self.assertTrue((d_output == v_output).all(), msg=msgs)
Beispiel #16
0
def test_3d_fallback_black_tophat():
    image = np.ones((7, 7, 7), dtype=bool)
    image[2, 2:4, 2:4] = 0
    image[3, 2:5, 2:5] = 0
    image[4, 3:5, 3:5] = 0

    with expected_warnings(['operator.*deprecated|\A\Z']):
        new_image = grey.black_tophat(image)
    footprint = ndi.generate_binary_structure(3, 1)
    with expected_warnings(['operator.*deprecated|\A\Z']):
        image_expected = ndi.black_tophat(image, footprint=footprint)
    assert_array_equal(new_image, image_expected)
Beispiel #17
0
def exer1():
    cells_binary = color.rgb2gray(io.imread('./Week 5/cells_binary.png'))

    # cells_binary = np.max(cells_binary) - cells_binary
    ball = disk(2)

    opened = opening(cells_binary, ball)
    closed = closing(cells_binary, ball)

    # fig, ax = plt.subplots(1, 3)
    # ax[0].imshow(cells_binary, cmap='gray')
    # ax[1].imshow(closed, cmap='gray')
    # ax[2].imshow(opened, cmap='gray')
    # plt.show()
    io.imsave('ball.png', ball)
    io.imsave('opened.png', opened)
    io.imsave('closed.png', closed)

    blobs_inv = io.imread('./Week 5/blobs_inv.png')
    blobs_inv = np.max(blobs_inv) - blobs_inv
    se0 = np.array([[1, 1, 1, 1, 1]])
    se1 = disk(2)
    print()
    print(se1)
    se2 = np.array([[0, 0, 0], [1, 1, 0], [1, 1, 0]])

    hitormiss0 = binary_hit_or_miss(blobs_inv, se0, origin1=[0, 2])
    hitormiss1 = binary_hit_or_miss(blobs_inv, se1, 1 - disk(12))
    hitormiss2 = binary_hit_or_miss(blobs_inv, se2, 1 - se2)

    top_hat0 = white_tophat(blobs_inv, se0)
    top_hat1 = white_tophat(blobs_inv, se1)
    top_hat2 = white_tophat(blobs_inv, se2)

    btop_hat0 = black_tophat(blobs_inv, se0)
    btop_hat1 = black_tophat(blobs_inv, se1)
    btop_hat2 = black_tophat(blobs_inv, se2)

    plt.imshow(hitormiss2, cmap='gray')
    plt.savefig('hitormiss2pdf')
Beispiel #18
0
def separate_lungs(image, return_list=None, iteration=-1):
    """
    This only takes in a 2D slice to make he lung segmentation and takes really long to run.
    But supposedly will get all corner cases. Not sure if mask from this is very good.
    Looks like the mask might be too dilated.

    :param image:
    :param return_list:
    :param iteration:
    :return:
    """
    #Creation of the markers as shown above:
    marker_internal, marker_external, marker_watershed = generate_markers(
        image)

    #Creation of the Sobel-Gradient
    sobel_filtered_dx = ndimage.sobel(image, 1)
    sobel_filtered_dy = ndimage.sobel(image, 0)
    sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
    sobel_gradient *= 255.0 / np.max(sobel_gradient)

    #Watershed algorithm
    watershed = morphology.watershed(sobel_gradient, marker_watershed)

    #Reducing the image created by the Watershed algorithm to its outline
    outline = ndimage.morphological_gradient(watershed, size=(3, 3))
    outline = outline.astype(bool)

    #Performing Black-Tophat Morphology for reinclusion
    #Creation of the disk-kernel and increasing its size a bit
    blackhat_struct = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0],
                       [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0],
                       [0, 0, 1, 1, 1, 0, 0]]
    blackhat_struct = ndimage.iterate_structure(blackhat_struct, 8)
    #Perform the Black-Hat
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)

    #Use the internal marker and the Outline that was just created to generate the lungfilter
    lungfilter = np.bitwise_or(marker_internal, outline)
    #Close holes in the lungfilter
    #fill_holes is not used here, since in some slices the heart would be reincluded by accident
    lungfilter = ndimage.morphology.binary_closing(lungfilter,
                                                   structure=np.ones((5, 5)),
                                                   iterations=3)

    # #Apply the lungfilter (note the filtered areas being assigned -2000 HU)
    # segmented = np.where(lungfilter == 1, image, -2000*np.ones((512, 512)))
    if iteration >= 0 and return_list:
        return_list[iteration] = lungfilter
    else:
        return lungfilter
Beispiel #19
0
    def fill_border_holes_with_black_hat(self, outline):

        blackhat_struct = [[0, 0, 1, 1, 1, 0, 0],
                           [0, 1, 1, 1, 1, 1, 0],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [0, 1, 1, 1, 1, 1, 0],
                           [0, 0, 1, 1, 1, 0, 0]]

        blackhat_struct = ndimage.iterate_structure(blackhat_struct, 2)
        outline += ndimage.black_tophat(outline, structure=blackhat_struct)

        return outline
    def seperate_lungs(image):
        """
        Function conducts lung segmentation process using watershed algorithm

        :param image: a pixel array
        :return: segmented, lungfilter, outline, watershed, sobel_gradient, marker_internal, marker_external, marker_watershed: 
        np ndarrays of segmented lungs (segmented) and other markers used in the process
        """
        # Creation of the markers as shown above:
        marker_internal, marker_external, marker_watershed = SegmentationA.generate_markers(
            image)

        # Creation of the Sobel-Gradient
        sobel_filtered_dx = ndimage.sobel(image, 1)
        sobel_filtered_dy = ndimage.sobel(image, 0)
        sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
        sobel_gradient *= 255.0 / np.max(sobel_gradient)

        # Watershed algorithm
        watershed = morphology.watershed(sobel_gradient, marker_watershed)

        # Reducing the image created by the Watershed algorithm to its outline
        outline = ndimage.morphological_gradient(watershed, size=(3, 3))
        outline = outline.astype(bool)

        # Performing Black-Tophat Morphology for reinclusion
        # Creation of the disk-kernel and increasing its size a bit
        blackhat_struct = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0],
                           [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0],
                           [0, 0, 1, 1, 1, 0, 0]]
        blackhat_struct = ndimage.iterate_structure(blackhat_struct, 8)

        # Perform the Black-Hat
        outline += ndimage.black_tophat(outline, structure=blackhat_struct)

        # Use the internal marker and the Outline that was just created to generate the lungfilter
        lungfilter = np.bitwise_or(marker_internal, outline)
        # Close holes in the lungfilter
        # fill_holes is not used here, since in some slices the heart would be reincluded by accident
        lungfilter = ndimage.morphology.binary_closing(lungfilter,
                                                       structure=np.ones(
                                                           (5, 5)),
                                                       iterations=3)

        # Apply the lungfilter (note the filtered areas being assigned -2000 HU)
        segmented = np.where(lungfilter == 1, image, -2000 * np.ones(
            (len(image), len(image[0]))))

        return segmented, lungfilter
Beispiel #21
0
	def __operationTask(self,input_var):
		'''
		perform respective moephological operation on input block.
        Parameters
        ----------
        input_var  	: type: 3d numpy array, ith block.		
		
        Returns
		-------
		output     : type: 3d array, output of operation, ith block array.
        '''
		
		
		D=self.__operationArgumentDic
		if self.__operation=="binary_closing":	
			return ndimage.binary_closing(input_var, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
		elif self.__operation=="binary_dilation":
			return ndimage.binary_dilation(input_var, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
		elif self.__operation=="binary_erosion":
			return ndimage.binary_erosion(input_var, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
		elif self.__operation=="binary_fill_holes": #the output might be different then scipy.ndimage  
			return ndimage.binary_fill_holes(input_var, structure=D["structure"],output=D["output"], origin=D["origin"])
		elif self.__operation=="binary_hit_or_miss":
			return ndimage.binary_hit_or_miss(input_var, structure1=D["structure1"],structure2=D["structure2"],output=D["output"], origin1=D["origin1"], origin2=D["origin2"])
		elif self.__operation=="binary_opening":
			return ndimage.binary_opening(input_var, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
		elif self.__operation=="binary_propagation":			
			return ndimage.binary_propagation(input_var, structure=D["structure"],output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"])
		elif self.__operation=="black_tophat":
			return ndimage.black_tophat(input_var, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
		elif self.__operation=="grey_dilation":
			return ndimage.grey_dilation(input_var, structure=D["structure"],size=D["size"], footprint=D["footprint"],output=D["output"], mode=D["mode"], cval=D["cval"], origin=D["origin"])			
		elif self.__operation=="grey_closing":
			return ndimage.grey_closing(input_var, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
		elif self.__operation=="grey_erosion":
			return ndimage.grey_erosion(input_var, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
		elif self.__operation=="grey_opening":
			return ndimage.grey_opening(input_var, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
		elif self.__operation=="morphological_gradient":
			return ndimage.morphological_gradient(input_var, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
		elif self.__operation=="morphological_laplace":
			return ndimage.morphological_laplace(input_var, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
		elif self.__operation=="white_tophat":
			return ndimage.white_tophat(input_var, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
		elif self.__operation=="multiply":
			return input_var*D["scalar"]		
		else:
			return input_var # no operation performed....
Beispiel #22
0
def get_segmented_lungs(image):
    #Creation of the markers as shown above:
    marker_internal, marker_external, marker_watershed = generate_markers(
        image)

    #Creation of the Sobel-Gradient
    sobel_filtered_dx = ndimage.sobel(image, 1)
    sobel_filtered_dy = ndimage.sobel(image, 0)
    sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
    sobel_gradient *= 255.0 / np.max(sobel_gradient)

    #Watershed algorithm
    watershed = morphology.watershed(sobel_gradient, marker_watershed)

    #Reducing the image created by the Watershed algorithm to its outline
    outline = ndimage.morphological_gradient(watershed, size=(3, 3))
    outline = outline.astype(bool)

    #Performing Black-Tophat Morphology for reinclusion
    #Creation of the disk-kernel and increasing its size a bit
    blackhat_struct = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0],
                       [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0],
                       [0, 0, 1, 1, 1, 0, 0]]
    #blackhat_struct = ndimage.iterate_structure(blackhat_struct, 8)
    blackhat_struct = ndimage.iterate_structure(
        blackhat_struct, 14
    )  # <- retains more of the area, 12 works well. Changed to 14, 12 still excluded some parts.
    #Perform the Black-Hat
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)

    #Use the internal marker and the Outline that was just created to generate the lungfilter
    lungfilter = np.bitwise_or(marker_internal, outline)
    #Close holes in the lungfilter
    #fill_holes is not used here, since in some slices the heart would be reincluded by accident
    lungfilter = ndimage.morphology.binary_closing(lungfilter,
                                                   structure=np.ones((5, 5)),
                                                   iterations=3)

    #Apply the lungfilter (note the filtered areas being assigned threshold_min HU)
    segmented = np.where(lungfilter == 1, image,
                         threshold_min * np.ones(image.shape))

    #return segmented, lungfilter, outline, watershed, sobel_gradient, marker_internal, marker_external, marker_watershed
    return segmented
def seperate_lungs(image, min_hu, iterations, threshold=-700):
    """
    Segments lungs using various techniques.
    
    Parameters: image (Scan image), iterations (more iterations, more accurate mask)
    
    Returns: 
        - Segmented Lung
    """

    h, w = image.shape[0], image.shape[1]

    marker_internal, marker_external, marker_watershed = generate_markers(
        image, threshold)

    # Sobel-Gradient
    sobel_filtered_dx = ndimage.sobel(image, 1)
    sobel_filtered_dy = ndimage.sobel(image, 0)
    sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)

    if np.max(sobel_gradient) == 0:
        return image

    sobel_gradient *= 255.0 / np.max(sobel_gradient)
    watershed = segmentation.watershed(sobel_gradient, marker_watershed)
    outline = ndimage.morphological_gradient(watershed, size=(3, 3))
    outline = outline.astype(bool)

    # Structuring element used for the filter
    blackhat_struct = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0],
                       [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0],
                       [0, 0, 1, 1, 1, 0, 0]]
    blackhat_struct = ndimage.iterate_structure(blackhat_struct, iterations)

    # Perform Black Top-hat filter
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)
    lungfilter = np.bitwise_or(marker_internal, outline)
    lungfilter = ndimage.morphology.binary_closing(lungfilter,
                                                   structure=np.ones((5, 5)),
                                                   iterations=3)
    segmented = np.where(lungfilter == 1, image, min_hu * np.ones((h, w)))
    return segmented
Beispiel #24
0
def get_segmented_lungs(image):
    #Creation of the markers as shown above:
    marker_internal, marker_external, marker_watershed = generate_markers(image)
    
    #Creation of the Sobel-Gradient
    sobel_filtered_dx = ndimage.sobel(image, 1)
    sobel_filtered_dy = ndimage.sobel(image, 0)
    sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
    sobel_gradient *= 255.0 / np.max(sobel_gradient)
    
    #Watershed algorithm
    watershed = morphology.watershed(sobel_gradient, marker_watershed)
    
    #Reducing the image created by the Watershed algorithm to its outline
    outline = ndimage.morphological_gradient(watershed, size=(3,3))
    outline = outline.astype(bool)
    
    #Performing Black-Tophat Morphology for reinclusion
    #Creation of the disk-kernel and increasing its size a bit
    blackhat_struct = [[0, 0, 1, 1, 1, 0, 0],
                       [0, 1, 1, 1, 1, 1, 0],
                       [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1],
                       [0, 1, 1, 1, 1, 1, 0],
                       [0, 0, 1, 1, 1, 0, 0]]
    #blackhat_struct = ndimage.iterate_structure(blackhat_struct, 8)
    blackhat_struct = ndimage.iterate_structure(blackhat_struct, 14) # <- retains more of the area, 12 works well. Changed to 14, 12 still excluded some parts.
    #Perform the Black-Hat
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)
    
    #Use the internal marker and the Outline that was just created to generate the lungfilter
    lungfilter = np.bitwise_or(marker_internal, outline)
    #Close holes in the lungfilter
    #fill_holes is not used here, since in some slices the heart would be reincluded by accident
    lungfilter = ndimage.morphology.binary_closing(lungfilter, structure=np.ones((5,5)), iterations=3)
    
    #Apply the lungfilter (note the filtered areas being assigned threshold_min HU)
    segmented = np.where(lungfilter == 1, image, threshold_min*np.ones(image.shape))
    
    #return segmented, lungfilter, outline, watershed, sobel_gradient, marker_internal, marker_external, marker_watershed
    return segmented
    def get_segmented_lungs(self, image, plot=False):
        # TODO: might add the logic for plotting the filters applied in the process
        #Creation of the markers as shown above:
        marker_internal, marker_external, marker_watershed = self.generate_markers(image)
        
        #Creation of the Sobel-Gradient
        sobel_filtered_dx = ndi.sobel(image, 1)
        sobel_filtered_dy = ndi.sobel(image, 0)
        sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
        sobel_gradient *= 255.0 / np.max(sobel_gradient)
        
        #Watershed algorithm
        watershed = morphology.watershed(sobel_gradient, marker_watershed)
        
        #Reducing the image created by the Watershed algorithm to its outline
        outline = ndi.morphological_gradient(watershed, size=(3,3))
        outline = outline.astype(bool)
        
        #Performing Black-Tophat Morphology for reinclusion
        #Creation of the disk-kernel and increasing its size a bit
        blackhat_struct = [[0, 0, 1, 1, 1, 0, 0],
                           [0, 1, 1, 1, 1, 1, 0],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [0, 1, 1, 1, 1, 1, 0],
                           [0, 0, 1, 1, 1, 0, 0]]
        blackhat_struct = ndi.iterate_structure(blackhat_struct, 8)
        #Perform the Black-Hat
        outline += ndi.black_tophat(outline, structure=blackhat_struct)
        
        #Use the internal marker and the Outline that was just created to generate the lungfilter
        lungfilter = np.bitwise_or(marker_internal, outline)
        #Close holes in the lungfilter
        #fill_holes is not used here, since in some slices the heart would be reincluded by accident
        lungfilter = ndi.morphology.binary_closing(lungfilter, structure=np.ones((5,5)), iterations=3)
        
        #Apply the lungfilter (the filtered areas being assigned 0 HU
        segmented = np.where(lungfilter == 1, image, np.zeros(image.shape))

        return segmented
def operationTask(input):
	D=operationArgumentDic
	#self.M.add_mem()#.....................................................................................................
	
	if operation=="binary_closing":	
		return ndimage.binary_closing(input, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
	elif operation=="binary_dilation":
		return ndimage.binary_dilation(input, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
	elif operation=="binary_erosion":
		return ndimage.binary_erosion(input, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
	elif operation=="binary_fill_holes":
		return ndimage.binary_fill_holes(input, structure=D["structure"],output=D["output"], origin=D["origin"])
	elif operation=="binary_hit_or_miss":
		return ndimage.binary_hit_or_miss(input, structure1=D["structure1"],structure2=D["structure2"],output=D["output"], origin1=D["origin1"], origin2=D["origin2"])
	elif operation=="binary_opening":
		return ndimage.binary_opening(input, structure=D["structure"], iterations=D["iterations"], output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"], brute_force=D["brute_force"])
	elif operation=="binary_propagation":			
		return ndimage.binary_propagation(input, structure=D["structure"],output=D["output"], origin=D["origin"], mask=D["mask"], border_value=D["border_value"])
	elif operation=="black_tophat":
		return ndimage.black_tophat(input, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
	elif operation=="grey_dilation":
		return ndimage.grey_dilation(input, structure=D["structure"],size=D["size"], footprint=D["footprint"],output=D["output"], mode=D["mode"], cval=D["cval"], origin=D["origin"])
	elif operation=="grey_closing":
		return ndimage.grey_closing(input, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
	elif operation=="grey_erosion":
		return ndimage.grey_erosion(input, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
	elif operation=="grey_opening":
		return ndimage.grey_opening(input, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
	elif operation=="morphological_gradient":
		return ndimage.morphological_gradient(input, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
	elif operation=="morphological_laplace":
		return ndimage.morphological_laplace(input, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
	elif operation=="white_tophat":
		return ndimage.white_tophat(input, structure=D["structure"], size=D["size"], footprint=D["footprint"],  output=D["output"], origin=D["origin"],mode=D["mode"], cval=D["cval"])
	elif operation=="intMultiply":
		return input*D["scalar"]
	
	else:
		return input
Beispiel #27
0
def Exer114():
    '''
    NOT USED

    Returns
    -------
    None.

    '''
    A = io.imread("./Week 5/cells_binary.png")

    def LargeOpening(I, n):

        for i in range(n):
            I = binary_erosion(I)
        for i in range(n):
            I = binary_dilation(I)

        return (I)

    fig_d = [1, 3]

    SE = A[367:395, 217:245]

    plt.figure()
    plt.subplot(fig_d[0], fig_d[1], 1)
    plotImage(gca(), opening(opening(SE)), 'SE_hit', gray=True)

    plt.subplot(fig_d[0], fig_d[1], 2)
    plotImage(gca(),
              black_tophat(opening(opening(A))[250:350, 350:450], ),
              'Opening',
              gray=True)

    plt.subplot(fig_d[0], fig_d[1], 3)
    plotImage(gca(),
              closing(closing(A)[250:350, 350:450]),
              'Closing',
              gray=True)
Beispiel #28
0
def water_regions(_probs, _points, return_dict=False):
    points = _points.copy()
    if return_dict:
        y_ind, x_ind = np.where(points != 0)
        yx_list = []
        for i in range(y_ind.shape[0]):
            label = i + 1
            points[y_ind[i], x_ind[i]] = label
            yx_list += [{"y": y_ind[i], "x": x_ind[i], "label": label}]

        points = points.astype(float)
    else:
        points[points != 0] = np.arange(1, points.sum() + 1)
        points = points.astype(float)

    probs = ndimage.black_tophat(_probs.copy(), 7)

    seg = watershed(probs, points)

    if return_dict:
        return {"seg": seg, "yx_list": yx_list}

    return seg
Beispiel #29
0
def threshold(img, radius, threshold):
    smoothed = nd.black_tophat(img, radius)
    difference = img - smoothed
    return difference > scoreatpercentile(difference[np.where(~np.isnan(difference))], threshold)
Beispiel #30
0
def seperateLungs(image, n_iters=2, only_internal=False, only_watershed=False):
    """
    Segments lungs using various techniques.
    
    Parameters: image (Scan image)
    
    Returns: 
        - Segmented Lung
        - Lung Filter
        - Outline Lung
        - Watershed Lung
        - Sobel Gradient
    """
    if only_internal:
        marker_internal = generateMarkers(image, only_internal)
    else:
        marker_internal, marker_external, marker_watershed = generateMarkers(
            image, only_internal)
    '''
    Creation of Sobel Gradient
    '''

    # Sobel-Gradient
    sobel_filtered_dx = ndimage.sobel(image, 1)
    sobel_filtered_dy = ndimage.sobel(image, 0)
    sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
    sobel_gradient *= 255.0 / np.max(sobel_gradient)
    '''
    Using the watershed algorithm
    
    
    We pass the image convoluted by sobel operator and the watershed marker
    to morphology.watershed and get a matrix matrix labeled using the 
    watershed segmentation algorithm.
    '''
    watershed = morphology.watershed(sobel_gradient, marker_watershed)

    if only_watershed:
        return watershed
    '''
    Reducing the image to outlines after Watershed algorithm
    '''
    outline = ndimage.morphological_gradient(watershed, size=(3, 3))
    outline = outline.astype(bool)
    '''
    Black Top-hat Morphology:
    
    The black top hat of an image is defined as its morphological closing
    minus the original image. This operation returns the dark spots of the
    image that are smaller than the structuring element. Note that dark 
    spots in the original image are bright spots after the black top hat.
    '''

    # Structuring element used for the filter
    blackhat_struct = [[0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 0],
                       [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
                       [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0],
                       [0, 0, 1, 1, 1, 0, 0]]

    blackhat_struct = ndimage.iterate_structure(blackhat_struct, n_iters)

    # Perform Black Top-hat filter
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)
    outline += ndimage.black_tophat(outline, structure=blackhat_struct)
    '''
    Generate lung filter using internal marker and outline.
    '''
    lungfilter = np.bitwise_or(marker_internal, outline)
    lungfilter = ndimage.morphology.binary_closing(lungfilter,
                                                   structure=np.ones((5, 5)),
                                                   iterations=3)
    '''
    Segment lung using lungfilter and the image.
    '''
    segmented = np.where(lungfilter == 1, image, -2000 * np.ones(image.shape))

    return segmented, lungfilter, outline, watershed, sobel_gradient
Beispiel #31
0
def seperate_lungs_and_pad(scan):
    
    # make total 256 slices fill in -1100 as exterme value 
    segmented_scan = np.full ((256, 512, 512), THRESHOLD_LOW)
    
    for i, image in enumerate (scan):
        
        # Ignore all slices later than 255 if required.
        if (i == 256):
            break
        
        # Creation of the internal Marker
        marker_internal = image < -400
        marker_internal = segmentation.clear_border(marker_internal)
        marker_internal_labels = measure.label(marker_internal)
        areas = [r.area for r in measure.regionprops(marker_internal_labels)]
        areas.sort()
        if len(areas) > 2:
            for region in measure.regionprops(marker_internal_labels):
                if region.area < areas[-2]:
                    for coordinates in region.coords:                
                           marker_internal_labels[coordinates[0], coordinates[1]] = 0
        marker_internal = marker_internal_labels > 0
        #Creation of the external Marker
        external_a = ndimage.binary_dilation(marker_internal, iterations=10)
        external_b = ndimage.binary_dilation(marker_internal, iterations=55)
        marker_external = external_b ^ external_a
        #Creation of the Watershed Marker matrix
        marker_watershed = np.zeros((512, 512), dtype=np.int)
        marker_watershed += marker_internal * 255
        marker_watershed += marker_external * 128

        #Creation of the Sobel-Gradient
        sobel_filtered_dx = ndimage.sobel(image, 1)
        sobel_filtered_dy = ndimage.sobel(image, 0)
        sobel_gradient = np.hypot(sobel_filtered_dx, sobel_filtered_dy)
        sobel_gradient *= 255.0 / np.max(sobel_gradient)

        #Watershed algorithm
        watershed = morphology.watershed(sobel_gradient, marker_watershed)

        #Reducing the image created by the Watershed algorithm to its outline
        outline = ndimage.morphological_gradient(watershed, size=(3,3))
        outline = outline.astype(bool)

        #Performing Black-Tophat Morphology for reinclusion
        #Creation of the disk-kernel and increasing its size a bit
        blackhat_struct = [[0, 0, 1, 1, 1, 0, 0],
                           [0, 1, 1, 1, 1, 1, 0],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [0, 1, 1, 1, 1, 1, 0],
                           [0, 0, 1, 1, 1, 0, 0]]
        blackhat_struct = ndimage.iterate_structure(blackhat_struct, 8)
        #Perform the Black-Hat
        outline += ndimage.black_tophat(outline, structure=blackhat_struct)

        #Use the internal marker and the Outline that was just created to generate the lungfilter
        lungfilter = np.bitwise_or(marker_internal, outline)
        #Close holes in the lungfilter
        #fill_holes is not used here, since in some slices the heart would be reincluded by accident
        lungfilter = ndimage.morphology.binary_closing(lungfilter, structure=np.ones((5,5)), iterations=3)

        #Apply the lungfilter (note the filtered areas being assigned 30 HU)
        segmented_scan[i] = np.where(lungfilter == 1, image, 30*np.ones((512, 512)))
        
    return segmented_scan
output = vc.black_tophat(input_var,
                         make_float32=False,
                         size=None,
                         footprint=None,
                         structure=structure,
                         output=None,
                         mode='reflect',
                         cval=0.0,
                         origin=0)
print("vc black_tophat: ", (t.time() - start_time), " sec")
print("\nblack_tophat Default")
start_time = t.time()
d = ndimage.black_tophat(input_var,
                         size=None,
                         footprint=None,
                         structure=structure,
                         output=None,
                         mode='reflect',
                         cval=0.0,
                         origin=0)
print("scipy black_tophat: ", (t.time() - start_time), " sec")
print("\nresult: ", (d == output).all())

#13.morphological_gradient..............
print("\nmorphological_gradient VoxelProcessing")
start_time = t.time()
output = vc.morphological_gradient(input_var,
                                   make_float32=False,
                                   size=None,
                                   footprint=None,
                                   structure=structure,
                                   output=None,
Beispiel #33
0
def main():
    structure = np.ones((3, 3, 3))
    #.............test1. dense.......
    filename = 'gyroidUniform.npy'
    input = np.load(filename, mmap_mode="r")

    print(
        "..............................dense.............................................."
    )

    #0.Nothing..............
    print("\n nothing testing...")
    output = vc.nothing(input, blockSize=50, fakeGhost=4, makeFloat32=False)
    print("\nresult: ", (input == output).all())
    print(output.dtype, input.dtype)
    #1.grey_dilation..............
    print("\ngrey_dilation VoxelProcessind")
    output = vc.grey_dilation(input, structure=structure, makeFloat32=False)
    print("\ngrey_dilation Default")
    d = ndimage.grey_dilation(input, structure=structure)
    print("\nresult: ", (d == output).all())
    print(output.dtype, input.dtype)
    #2.grey_erosion..............
    print("\ngrey_erosion VoxelProcessind")
    output = vc.grey_erosion(input,
                             makeFloat32=False,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\ngrey_erosion Default")
    d = ndimage.grey_erosion(input,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\nresult: ", (d == output).all())
    #3.grey_closing..............
    print("\ngrey_closing VoxelProcessind")
    output = vc.grey_closing(input,
                             makeFloat32=False,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\ngrey_closing Default")
    d = ndimage.grey_closing(input,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\nresult: ", (d == output).all())
    print(output.dtype, input.dtype)
    #4.grey_opening..............
    print("\ngrey_opening VoxelProcessind")
    output = vc.grey_opening(input,
                             makeFloat32=False,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\ngrey_opening Default")
    d = ndimage.grey_opening(input,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\nresult: ", (d == output).all())
    #5.binary_closing..............
    print("\nbinary_closing VoxelProcessind")
    output = vc.binary_closing(input,
                               makeFloat32=False,
                               structure=None,
                               iterations=1,
                               output=None,
                               origin=0,
                               mask=None,
                               border_value=0,
                               brute_force=False)
    print("\nbinary_closing Default")
    d = ndimage.binary_closing(input,
                               structure=None,
                               iterations=1,
                               output=None,
                               origin=0,
                               mask=None,
                               border_value=0,
                               brute_force=False)
    print("\nresult: ", (d == output).all())
    print(output[151][151][151])
    #6.binary_opening..............
    print("\nbinary_opening VoxelProcessind")
    output = vc.binary_opening(input,
                               structure=None,
                               iterations=1,
                               output=None,
                               origin=0,
                               mask=None,
                               border_value=0,
                               brute_force=False)
    print("\nbinary_opening Default")
    d = ndimage.binary_opening(input,
                               structure=None,
                               iterations=1,
                               output=None,
                               origin=0,
                               mask=None,
                               border_value=0,
                               brute_force=False)
    print("\nresult: ", (d == output).all())
    #7.binary_dilation..............
    print("\nbinary_dilation VoxelProcessind")
    output = vc.binary_dilation(input,
                                makeFloat32=False,
                                structure=structure,
                                iterations=1,
                                mask=None,
                                output=None,
                                border_value=0,
                                origin=0,
                                brute_force=False)
    print("\nbinary_dilation Default")
    d = ndimage.binary_dilation(input,
                                structure=structure,
                                iterations=1,
                                mask=None,
                                output=None,
                                border_value=0,
                                origin=0,
                                brute_force=False)
    print("\nresult: ", (d == output).all())
    #8.binary_erosion..............
    print("\nbinary_erosion VoxelProcessind")
    output = vc.binary_erosion(input,
                               makeFloat32=False,
                               structure=None,
                               iterations=1,
                               mask=None,
                               output=None,
                               border_value=0,
                               origin=0,
                               brute_force=False)
    print("\nbinary_erosion Default")
    d = ndimage.binary_erosion(input,
                               structure=None,
                               iterations=1,
                               mask=None,
                               output=None,
                               border_value=0,
                               origin=0,
                               brute_force=False)
    print("\nresult: ", (d == output).all())
    #9.binary_fill_holes..............
    print("\nbinary_fill_holes VoxelProcessind")
    output = vc.binary_fill_holes(input,
                                  makeFloat32=False,
                                  structure=None,
                                  output=None,
                                  origin=0)
    print("\nbinary_fill_holes Default")
    d = ndimage.binary_fill_holes(input, structure=None, output=None, origin=0)
    print("\nresult: ", (d == output).all())
    #10.binary_hit_or_miss..............
    print("\nbinary_hit_or_miss VoxelProcessind")
    output = vc.binary_hit_or_miss(input,
                                   makeFloat32=False,
                                   structure1=None,
                                   structure2=None,
                                   output=None,
                                   origin1=0,
                                   origin2=None)
    print("\nbinary_hit_or_miss Default")
    d = ndimage.binary_hit_or_miss(input,
                                   structure1=None,
                                   structure2=None,
                                   output=None,
                                   origin1=0,
                                   origin2=None)
    print("\nresult: ", (d == output).all())
    #11.binary_propagation..............
    print("\nbinary_propagation VoxelProcessind")
    output = vc.binary_propagation(input,
                                   makeFloat32=False,
                                   structure=None,
                                   mask=None,
                                   output=None,
                                   border_value=0,
                                   origin=0)
    print("\nbinary_propagation Default")
    d = ndimage.binary_propagation(input,
                                   structure=None,
                                   mask=None,
                                   output=None,
                                   border_value=0,
                                   origin=0)
    print("\nresult: ", (d == output).all())
    #12.black_tophat..............
    print("\nblack_tophat VoxelProcessind")
    output = vc.black_tophat(input,
                             makeFloat32=False,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\nblack_tophat Default")
    d = ndimage.black_tophat(input,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\nresult: ", (d == output).all())
    #13.morphological_gradient..............
    print("\nmorphological_gradient VoxelProcessind")
    output = vc.morphological_gradient(input,
                                       makeFloat32=False,
                                       size=None,
                                       footprint=None,
                                       structure=structure,
                                       output=None,
                                       mode='reflect',
                                       cval=0.0,
                                       origin=0)
    print("\nmorphological_gradient Default")
    d = ndimage.morphological_gradient(input,
                                       size=None,
                                       footprint=None,
                                       structure=structure,
                                       output=None,
                                       mode='reflect',
                                       cval=0.0,
                                       origin=0)
    print("\nresult: ", (d == output).all())
    #14.morphological_laplace..............
    print("\nmorphological_laplace VoxelProcessind")
    output = vc.morphological_laplace(input,
                                      makeFloat32=False,
                                      size=None,
                                      footprint=None,
                                      structure=structure,
                                      output=None,
                                      mode='reflect',
                                      cval=0.0,
                                      origin=0)
    print("\nmorphological_laplace Default")
    d = ndimage.morphological_laplace(input,
                                      size=None,
                                      footprint=None,
                                      structure=structure,
                                      output=None,
                                      mode='reflect',
                                      cval=0.0,
                                      origin=0)
    print("\nresult: ", (d == output).all())
    #15.white_tophat..............
    print("\nwhite_tophat VoxelProcessind")
    output = vc.white_tophat(input,
                             makeFloat32=False,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\nwhite_tophat VoxelProcessind Default")
    d = ndimage.white_tophat(input,
                             size=None,
                             footprint=None,
                             structure=structure,
                             output=None,
                             mode='reflect',
                             cval=0.0,
                             origin=0)
    print("\nresult: ", (d == output).all())
    #16.intMultiply..............
    print("\nintMultiply VoxelProcessind")
    output = vc.intMultiply(input,
                            makeFloat32=False,
                            blockSize=50,
                            fakeGhost=1,
                            scalar=10)
    print("\nintMultiply Default")
    d = input * 10
    print("\nresult: ", (d == output).all())

    print(
        "..............................Sparse.............................................."
    )

    input = random(400, 80000, density=0.3, dtype="float64")
    input = input.todense()
    input = np.array(input)
    input = np.reshape(input, (400, 200, 400))

    #0.Nothing..............
    print("\n nothing testing...")
    output = vc.nothing(input, makeFloat32=False)
    print("\nresult: ", (input == output).all())
    print(output.dtype, input.dtype)
    #1.grey_dilation..............
    print("\ngrey_dilation VoxelProcessind")
    output = vc.grey_dilation(input, structure=structure, makeFloat32=False)
    print("\ngrey_dilation Default")
    d = ndimage.grey_dilation(input, structure=structure)
    print("\nresult: ", (d == output).all())
    print(output.dtype, input.dtype)
    #2.grey_erosion..............
    print("\ngrey_erosion VoxelProcessind")
    output = vc.grey_erosion(input, makeFloat32=False, structure=structure)
    print("\ngrey_erosion Default")
    d = ndimage.grey_erosion(input, structure=structure)
    print("\nresult: ", (d == output).all())
    #3.grey_closing..............
    print("\ngrey_closing VoxelProcessind")
    output = vc.grey_closing(input, makeFloat32=False, structure=structure)
    print("\ngrey_closing Default")
    d = ndimage.grey_closing(input, structure=structure)
    print("\nresult: ", (d == output).all())
    print(output.dtype, input.dtype)
    #4.grey_opening..............
    print("\ngrey_opening VoxelProcessind")
    output = vc.grey_opening(input, makeFloat32=False, structure=structure)
    print("\ngrey_opening Default")
    d = ndimage.grey_opening(input, structure=structure)
    print("\nresult: ", (d == output).all())
    #5.binary_closing..............
    print("\nbinary_closing VoxelProcessind")
    output = vc.binary_closing(input, makeFloat32=False)
    print("\nbinary_closing Default")
    d = ndimage.binary_closing(input)
    print("\nresult: ", (d == output).all())
    #6.binary_opening..............
    print("\nbinary_opening VoxelProcessind")
    output = vc.binary_opening(input, makeFloat32=False)
    print("\nbinary_opening Default")
    d = ndimage.binary_opening(input)
    print("\nresult: ", (d == output).all())
    #7.binary_dilation..............
    print("\nbinary_dilation VoxelProcessind")
    output = vc.binary_dilation(input, makeFloat32=False, structure=structure)
    print("\nbinary_dilation Default")
    d = ndimage.binary_dilation(input, structure=structure)
    print("\nresult: ", (d == output).all())
    #8.binary_erosion..............
    print("\nbinary_erosion VoxelProcessind")
    output = vc.binary_erosion(input, makeFloat32=False)
    print("\nbinary_erosion Default")
    d = ndimage.binary_erosion(input)
    print("\nresult: ", (d == output).all())
    #9.binary_fill_holes..............
    print("\nbinary_fill_holes VoxelProcessind")
    output = vc.binary_fill_holes(input, makeFloat32=False)
    print("\nbinary_fill_holes Default")
    d = ndimage.binary_fill_holes(input)
    print("\nresult: ", (d == output).all())
    #10.binary_hit_or_miss..............
    print("\nbinary_hit_or_miss VoxelProcessind")
    output = vc.binary_hit_or_miss(input, makeFloat32=False)
    print("\nbinary_hit_or_miss Default")
    d = ndimage.binary_hit_or_miss(input)
    print("\nresult: ", (d == output).all())
    #11.binary_propagation..............
    print("\nbinary_propagation VoxelProcessind")
    output = vc.binary_propagation(input, makeFloat32=False)
    print("\nbinary_propagation Default")
    d = ndimage.binary_propagation(input)
    print("\nresult: ", (d == output).all())
    #12.black_tophat..............
    print("\nblack_tophat VoxelProcessind")
    output = vc.black_tophat(input, makeFloat32=False, structure=structure)
    print("\nblack_tophat Default")
    d = ndimage.black_tophat(input, structure=structure)
    print("\nresult: ", (d == output).all())
    #13.morphological_gradient..............
    print("\nmorphological_gradient VoxelProcessind")
    output = vc.morphological_gradient(
        input,
        structure=structure,
        makeFloat32=False,
    )
    print("\nmorphological_gradient Default")
    d = ndimage.morphological_gradient(input, structure=structure)
    print("\nresult: ", (d == output).all())
    #14.morphological_laplace..............
    print("\nmorphological_laplace VoxelProcessind")
    output = vc.morphological_laplace(input,
                                      structure=structure,
                                      makeFloat32=False)
    print("\nmorphological_laplace Default")
    d = ndimage.morphological_laplace(input, structure=structure)
    print("\nresult: ", (d == output).all())
    #15.white_tophat..............
    print("\nwhite_tophat VoxelProcessind")
    output = vc.white_tophat(input, makeFloat32=False, structure=structure)
    print("\nwhite_tophat VoxelProcessind Default")
    d = ndimage.white_tophat(input, structure=structure)
    print("\nresult: ", (d == output).all())
    #16.intMultiply..............
    print("\nintMultiply VoxelProcessind")
    output = vc.intMultiply(input, makeFloat32=False, scalar=10)
    print("\nintMultiply Default")
    d = input * 10
    print("\nresult: ", (d == output).all())