Beispiel #1
0
 def test_show(self):
     path = './test_data/1_nd/CT_analyses/2DGaussianSmoothing/'
     self.ReadImage = ReadImage(path)
     list_of_image = self.ReadImage.openImage()
     for Z in list_of_image:
         imshow(Z.Image3D, cmap='gray')
         show()
Beispiel #2
0
    def test_show(self):
        path = './test_data/1_nd/CT_analyses/3DDoG/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()

        for Z in list_of_image:

            visualization3D(Z)
Beispiel #3
0
    def __init__(self, path):
        """
        Find local extrema without edges in LoG space
        """
        self.path = path
        self.min_list = []
        self.max_list = []

        self.ReadImage = ReadImage(path)
Beispiel #4
0
    def __init__(self, path, dim):
        self.path = path
        if dim == 2:

            self.open_path = '2DGaussianSmoothing/'

            self.path_to_save = '/2DDoG/'
        elif dim == 3:
            self.open_path = '3DGaussianSmoothing/'
            self.path_to_save = '3DDoG/'
        else:
            raise (str(dim), "dimension is wrong")

        self.ReadImage = ReadImage(self.path + self.open_path)
Beispiel #5
0
    def __init__(self, path, path_mask='', flag=False):
        """
        Find local extrema without edges in one image
        """
        self.flag = flag
        self.path_mask = path_mask
        self.mask = ReadMask(path_mask).openMask()
        self.true_array = np.ones((3, 3, 3), dtype=np.bool)
        self.false_array = -self.true_array
        self.true_array[1, 1, 1] = False

        self.min_list = []
        self.max_list = []
        self.path = path
        self.ReadImage = ReadImage(path)
Beispiel #6
0
    def test_show(self):
        path = './test_data/1_nd/CT_analyses/3DDoG/DoGSpaceExtremum3D/'
        list_with_images = ReadImage(path).openImage()
        keypoints_vizualization(list_with_images[-1])

        for z in list_with_images:
            keypoints_vizualization(z)
Beispiel #7
0
    def SIFTgrain(self, octave):
        path_analyse = '/CT_analysesClassification/' + octave
        octaves = 6

        initial_sigma = 1.1
        gauss = GaussianSmoothing3D(self.path + path_analyse,
                                    octaves).smoothing(initial_sigma)
        dimension = 3

        dog = DoG(self.path + path_analyse, dimension)
        dog.apply()
        pathDoG = '/3DDoG/'
        local_extrema = LocalExterma3D(self.path + path_analyse + pathDoG,
                                       self.path + path_analyse, True)
        local_extrema.find()
        path_local_extrema = '/3DLocalExtremum/'
        extrema = ExtremaSpace3D(self.path + path_analyse + pathDoG +
                                 path_local_extrema)
        extrema.find()
        Hessian = HessianMatrix(5.0)
        Hessian.HessianElimination(self.path + path_analyse)

        keypointorientation = KeyPointOrientation(self.path + path_analyse)
        keypointorientation.apply()
        path_keypoint_orientation = '/KeyPointsOrientation/'
        images = ReadImage(self.path + path_analyse +
                           path_keypoint_orientation).openImage()
        for im in images:
            rotateImage(im, 10, self.path + path_analyse).apply()

        path_discriptor = '/Descriptor3D/'
        keydis = KeypointsFeatures(self.path + path_analyse + path_discriptor,
                                   self.path + path_analyse).apply()
 def test_show(self):
     path = './test_data/1_nd/CT_analyses/2DGaussianSmoothing/'
     self.ReadImage = ReadImage(path)
     list_of_image = self.ReadImage.openImage()
     for Z in list_of_image:
         imshow(Z.Image3D, cmap='gray')
         show()
Beispiel #9
0
class DoG(object):
    def __init__(self, path, dim):
        self.path = path
        if dim == 2:

            self.open_path = '2DGaussianSmoothing/'

            self.path_to_save = '/2DDoG/'
        elif dim == 3:
            self.open_path = '3DGaussianSmoothing/'
            self.path_to_save = '3DDoG/'
        else:
            raise (str(dim), "dimension is wrong")

        self.ReadImage = ReadImage(self.path + self.open_path)
        # make directory

    def apply(self):
        list_of_image = self.ReadImage.openImage()
        saving = SaveImage(self.path + self.path_to_save)
        import numpy as np
        for i in range(0, len(list_of_image) - 1):

            DoG = list_of_image[i + 1].Image3D - list_of_image[i].Image3D
            print('before', np.min(DoG), np.max(DoG))
            DoG = normalize(DoG, [-1, 1], [0, 1])
            print(DoG.dtype)
            print(np.min(DoG), np.max(DoG))
            list_of_image[i].Image3D = DoG
            saving.saveImage(list_of_image[i])
def DeterminePlayerNames():

    # Take a screenshot
    myScreenShot = pyautogui.screenshot()
    myScreenShot.save(r"images\PlayerNames_File.png")

    # Read Image
    img = ReadImage("PlayerNames_File.png")

    # Cropping for player names
    y=120
    h=700
    x=1650
    w=178
    img = img[y:y+h, x:x+w]

    # Process image
    img = ProcessImage(img)
    # Show
    cv2.imshow('Image', img)
    cv2.waitKey(0)
    cv2.destroyWindow('Image')
    # Text interpret
    text = pytesseract.image_to_string(img)

    # Split and filter text
    text = text.split("\n") # Split text by new lines
    text = [string for string in text if string != ""] # Get rid of empty strings
    player_list = [string for string in text if len(string) > 2] # Get rid of strings < 2 in size (Assumption)

    # Get player names
    #player_list = [string for string in player_list if not string.isdigit()]
    #health_list = [string for string in ]
    print ("Looks like we'll be fighting:")
    print(player_list)
Beispiel #11
0
def DetermineOpponent():

    # Wait for opponent to load
    time.sleep(1)
    Opponent = [""]
    iter = 0
    max_iter = 3
    while Opponent[0] == '':
        iter = iter + 1
        # Take a screenshot
        myScreenShot = pyautogui.screenshot()
        myScreenShot.save(r"images\Opponent_File.png")

        # Read in image
        img  = ReadImage('Opponent_File.png')

        # Debug opponent image
        #img = ReadImage('Sample_Opponent2.png')

        # Cropping
        y=20
        h=45
        x=1220
        w=300
        img = img[y:y+h, x:x+w]

        # Process image
        #img = ProcessImage(img)

        # Grayscale
        img = cvtColor(img,COLOR_BGR2GRAY)

        # Color thresholding
        _,img = threshold(img,160,255,THRESH_BINARY)
        img = cv2.bitwise_not(img) # Invert black/white
        # Sharpen
        sharpening_kernal = np.array([[-1,-1,-1],
                                      [-2, 11 ,-2],
                                      [-1,-1,-1]])

        img = cv2.filter2D(img, -1, sharpening_kernal)



        # Show
        cv2.imshow('Image', img)
        cv2.waitKey(0)
        cv2.destroyWindow('Image')

        # Text interpret
        text = pytesseract.image_to_string(img)

        # Grab Phase
        Opponent = text.split("\n")
        print(Opponent)

        if(iter == max_iter):
            print("Done trying to find opponents!")
            break
Beispiel #12
0
    def test_show(self):
        path = './test_data/1_nd/CT_analyses/3DDoG/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()

        for Z in list_of_image:

            visualization3D(Z)
Beispiel #13
0
    def __init__(self, path):
        """
        Find local extrema without edges in LoG space
        """
        self.path = path
        self.min_list = []
        self.max_list = []

        self.ReadImage = ReadImage(path)
Beispiel #14
0
class DoG2DTest(unittest.TestCase):
    def setUp(self):
        self.path = './test_data/1_nd/CT_analyses/'
        self.dog = DoG(self.path, 2)

    def test_smoothing(self):
        self.dog.apply()

    def test_min(self):
        path = './test_data/1_nd/CT_analyses/2DDoG/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()
        for z in list_of_image:
            print min(z.Image3D),max(z.Image3D),z.sigma

    def test_show(self):
        path = './test_data/1_nd/CT_analyses/2DDoG/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()
        for Z in list_of_image:
            visualization2D(Z.Image3D)
Beispiel #15
0
class DoG2DTest(unittest.TestCase):
    def setUp(self):
        self.path = './test_data/1_nd/CT_analyses/'
        self.dog = DoG(self.path, 2)

    def test_smoothing(self):
        self.dog.apply()

    def test_min(self):
        path = './test_data/1_nd/CT_analyses/2DDoG/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()
        for z in list_of_image:
            print min(z.Image3D), max(z.Image3D), z.sigma

    def test_show(self):
        path = './test_data/1_nd/CT_analyses/2DDoG/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()
        for Z in list_of_image:
            visualization2D(Z.Image3D)
Beispiel #16
0
    def HessianElimination(self, path):
        """
        :param path: path to CT analyses folder
        :return:void saving images aggregator
        """

        path = path
        path_to_save = '/Hessian3D/'

        saving = SaveImage(path + path_to_save)
        ReadIm = ReadImage(path + '/3DDoG/DoGSpaceExtremum3D/')
        # ImagesDOG = ReadImage(path + '/3DDoG/').openImage()
        im = ReadIm.openImage()

        for i in range(0, len(im)):
            if im[i].keypoints_min.shape[0] != 0:
                im[i].keypoints_min = self.HessianValues(im[i], im[i].keypoints_min)

            if im[i].keypoints_max.shape[0] != 0:
                im[i].keypoints_max = self.HessianValues(im[i], im[i].keypoints_max)

            saving.saveImage(im[i])
Beispiel #17
0
    def __init__(self, path, octave_size):
        """

        :param path:path to directory with original images
        :param octave_size: Nos of images in one octave. If it is not odd , it will plus one.

        """
        self.path = path
        self.octave_size = octave_size + octave_size % 2
        self.k = sqrt(2)
        self.image = ReadImage(self.path).openImage()[0]
        self.spacing = self.image.spacing
        self.powers = np.arange(0, self.octave_size) / 3.0
Beispiel #18
0
    def __init__(self, path):
        self.path = path
        path_for_keypoints = path + '/Hessian3D/'
        path_for_Gaussian = path + '/3DGaussianSmoothing'
        self.ImageReader = ReadImage(path_for_Gaussian)
        self.PointReader = ReadImage(path_for_keypoints)
        self.list_with_keyponits = self.PointReader.openImage()
        self.spacing = self.list_with_keyponits[0].spacing
        self.size_in_pixels_xy = 3
        sigma_x = self.size_in_pixels_xy*1.5  # list_with_keyponits[0].sigma * 2 mask size is 9


        x_range = np.arange(0, self.size_in_pixels_xy + 1)
        self.pixel_distance_x = np.sort(np.concatenate((-x_range[1:], x_range)))
        self.size_of_window_x = self.size_in_pixels_xy
        self.size_of_window_z = self.size_in_pixels_xy
        self.X, self.Y, self.Z = np.meshgrid(self.pixel_distance_x, self.pixel_distance_x,
                                             self.pixel_distance_x)
        # self.X, self.Y = np.meshgrid(self.pixel_distance_x, self.pixel_distance_x)
        # to dla 1.5 sigmy

        self.gaussian_weight = np.exp(-((self.X ** 2 + self.Y ** 2 + self.Z ** 2) / (2 * (sigma_x / 2) ** 2)))
def DetermineIfCombat():
    # Find Combat phase
    Combat = 0
    iterator = 0
    max_iter = 50
    while Combat != 1:
        iterator = iterator + 1

        # Take a screenshot
        myScreenShot = pyautogui.screenshot()
        myScreenShot.save(r"images\Phase_File.png")

        # Read in image
        img = ReadImage('Phase_File.png')

        # Debug image file
        #print("DEBUG combat phase file")
        #img = ReadImage('Sample_CombatPhase.png')

        # Cropping
        y = 160
        h = 150
        x = 830
        w = 300
        img = img[y:y + h, x:x + w]

        # Process image
        img = ProcessImage(img)
        # Show
        #cv2.imshow('Image', img)

        # Text interpret
        text = pytesseract.image_to_string(img)

        # Grab Phase
        current_phase = text.split("\n")

        if (current_phase[0] == 'Planning'):
            print("It's' Planning Phase!")

        if (current_phase[0] == 'Combat'):
            print("It's Combat Phase!")
            DetermineOpponent()

        # Wait a little bit
        time.sleep(0.5)

        # Max iterator
        if (iterator == max_iter):
            print("MAX ITERATOR HIT! Quitting...")
            break
def result():
    image = []
    for filename in os.listdir('Static/tmp'):
        image.append(os.path.join('Static/tmp', filename))

    user_stats = ReadImage(image[0], local=True)
    os.remove(image[0])
    s = user_stats._getdata
    return '''<html> <head>    
    <link rel="stylesheet" 
    href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" 
    integrity= "" # I believe I had a key in here. 
    crossorigin="anonymous">
    </head><body>''' + s + "</body></html>"
Beispiel #21
0
    def HessianElimination(self, path):
        """
        :param path: path to CT analyses folder
        :return:void saving images aggregator
        """

        path = path
        path_to_save = '/Hessian3D/'

        saving = SaveImage(path + path_to_save)
        ReadIm = ReadImage(path + '/3DDoG/DoGSpaceExtremum3D/')
        # ImagesDOG = ReadImage(path + '/3DDoG/').openImage()
        im = ReadIm.openImage()

        for i in range(0, len(im)):
            if im[i].keypoints_min.shape[0] != 0:
                im[i].keypoints_min = self.HessianValues(
                    im[i], im[i].keypoints_min)

            if im[i].keypoints_max.shape[0] != 0:
                im[i].keypoints_max = self.HessianValues(
                    im[i], im[i].keypoints_max)

            saving.saveImage(im[i])
Beispiel #22
0
    def apply(self):
        organs_dic = {}
        masks = ReadMask(self.path).openMask()
        for organ in self.organs_names:
            organs_dic[organ] = zoom((eval('masks.' + organ)), self.resize_factor, order=1, mode='nearest',
                                     prefilter=True)

        new_masks = Masks(organs_dic['prostate'], organs_dic['bladder'], organs_dic['rectum'],
                          organs_dic['femurR'], organs_dic['femurL'], organs_dic['semi_vesicle'])
        SaveMask(self.path[:-2] + str(self.octave_nd) + '/').saveMask(new_masks)
        list_temp = ReadImage(self.path + '3DGaussianSmoothing').openImage()
        image3D = list_temp[int(len(list_temp) / 2.)]
        image3D.Image3D = zoom(image3D.Image3D, self.resize_factor, order=1, mode='nearest', prefilter=True)
        image3D.spacing=image3D.spacing*2.
        SaveIm = SaveImage(self.path[:-2] + str(self.octave_nd) + '/')
        SaveIm.saveImage(image3D)
Beispiel #23
0
class Gauss2DTest(unittest.TestCase):
    def setUp(self):
        self.path = './test_data/1_nd/CT_analyses/'
        octaves = 6
        self.gauss = GaussianSmoothing2D(self.path, octaves)

    def test_soothing(self):
        sigma = 1.1
        self.gauss.smoothing(sigma)

    def test_show(self):
        path = './test_data/1_nd/CT_analyses/2DGaussianSmoothing/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()
        for Z in list_of_image:
            imshow(Z.Image3D, cmap='gray')
            show()
class Gauss2DTest(unittest.TestCase):
    def setUp(self):
        self.path ='./test_data/1_nd/CT_analyses/'
        octaves = 6
        self.gauss = GaussianSmoothing2D(self.path, octaves)

    def test_soothing(self):
        sigma = 1.1
        self.gauss.smoothing(sigma)

    def test_show(self):
        path = './test_data/1_nd/CT_analyses/2DGaussianSmoothing/'
        self.ReadImage = ReadImage(path)
        list_of_image = self.ReadImage.openImage()
        for Z in list_of_image:
            imshow(Z.Image3D, cmap='gray')
            show()
Beispiel #25
0
    def apply(self):

        path = '/CT_analysesClassification/'
        octave_dict={}
        octave_dict[1]=[]
        octave_dict[2]=[]
        octave_dict[3]=[]
        for i in range(1, 43):

            try:
                path = self.path+'/'+ str(i) + '_nd//CT_analysesClassification/'
                if not os.path.exists(path):
                    raise IOError
            except IOError:
                continue

            for o in range(1, 4):
                k=0
                path_temp = path + str(o) + '/FullFeature/'
                print(path_temp)
                feature_list = FeatureReader(path_temp).open()
                image_list=ReadImage(path_temp).openImage()
                print(len(feature_list),len(image_list))
                for feature,image in zip(feature_list,image_list):
                    for orgnas in self.organs_names:
                        if eval('feature.'+orgnas+'_keypoints.size') != 0:
                            for e in eval('feature.'+orgnas+'_keypoints'):
                                k=k+1


                                self.list_with_features_object[orgnas].append(concatenate((image.Image3D[e[0]-2:e[0]+3,e[1]-2:e[1]+3,e[2]].flatten(),[i])))




                octave_dict[o].append(k)
Beispiel #26
0
class LocalExterma3D(object):
    def __init__(self, path, path_mask='', flag=False):
        """
        Find local extrema without edges in one image
        """
        self.flag = flag
        self.path_mask = path_mask
        self.mask = ReadMask(path_mask).openMask()
        self.true_array = np.ones((3, 3, 3), dtype=np.bool)
        self.false_array = -self.true_array
        self.true_array[1, 1, 1] = False

        self.min_list = []
        self.max_list = []
        self.path = path
        self.ReadImage = ReadImage(path)

    def find_one(self, image3D):
        """
        :param image3D: DoG Image as Image object
        :return: void
        """
        self.min_list = []
        self.max_list = []
        image3D = image3D.Image3D
        shape = image3D.shape
        start = clock()
        for i in range(1, shape[0]):
            for j in range(1, shape[1]):
                for z in range(1, shape[2]):
                    if self.flag == True and self.mask.sum_mask[i, j, z]==0:
                        continue # this is fast version

                    bool_array = image3D[i, j, z] > image3D[i - 1:i + 2, j - 1:j + 2, z - 1:z + 2]
                    sum = np.sum(bool_array)
                    if sum == 0:
                            self.min_list.append(np.array([i, j, z]))

                    elif sum == 26 and bool_array[1, 1, 1] == False:
                            self.max_list.append(np.array([i, j, z]))
        print(len(self.max_list), len(self.min_list))
        end = clock() - start
        print end

    def find(self):
        list_with_images = self.ReadImage.openImage()
        path_to_save = '/3DLocalExtremum/'
        saving = SaveImage(self.path + path_to_save)
        saving.saveImage(list_with_images[0])
        saving.saveImage(list_with_images[len(list_with_images) - 1])
        for i in range(1, len(list_with_images) - 1):
            self.find_one(list_with_images[i])
            min3D, max3D = self.get_min_max()

            print(min3D.shape, max3D.shape)
            list_with_images[i].keypoints_min = min3D
            list_with_images[i].keypoints_max = max3D
            saving.saveImage(list_with_images[i])
            print('image nr' + str(i) + 'done')


    def get_min_max(self):
        """
        :return: list of indexes as a np.array min and max [i,j,z]
        """
        return np.array(self.min_list), np.array(self.max_list)
Beispiel #27
0
 def __init__(self, path_images, path_mask):
     self.images = ReadImage(path_images).openImage()
     self.masks = ReadMask(path_mask).openMask()
     self.Save = SaveImage(path_mask + '/FullFeature/')
     self.organs_names = ['rectum', 'prostate', 'bladder', 'femurL', 'femurR', 'semi_vesicle']
     self.SaveFeatures = SaveFeatures(path_mask + '/FullFeature/')
Beispiel #28
0
 def test_ReadImage(self):
     im = ReadImage(self.path + 'CT_analyses/').openImage()
     visualization3D(im[0])
Beispiel #29
0
 def test_min(self):
     path = './test_data/1_nd/CT_analyses/3DDoG/'
     self.ReadImage = ReadImage(path)
     list_of_image = self.ReadImage.openImage()
     for z in list_of_image:
         print min(z.Image3D),max(z.Image3D),z.sigma
Beispiel #30
0
 def __init__(self, path_images, path_mask):
     self.images = ReadImage(path_images).openImage()
     self.masks = ReadMask(path_mask).openMask()
     self.Save = SaveImage(path_mask + '/FullFeature/')
Beispiel #31
0
 def setUp(self):
     self.open = ReadImage(
         './test_data/1_nd/CT_analyses/KeyPointsOrientation/').openImage()
     self.rotate = rotateImage(self.open[0], 10,
                               './test_data/1_nd/CT_analyses/')
 def test_visualization(self):
     path = './test_data/1_nd/CT_analyses/KeyPointsOrientation/'
     list_with_images = ReadImage(path).openImage()
     for z in list_with_images:
         keypointsOrinetation_vizualization(z)
Beispiel #33
0
 def test_show(self):
     list_of_image = ReadImage(
         './test_data/1_nd/CT_analyses/3DGaussianSmoothing/').openImage()
     for Z in list_of_image:
         visualization3D(Z)
Beispiel #34
0
 def test_min(self):
     path = './test_data/1_nd/CT_analyses/3DDoG/'
     self.ReadImage = ReadImage(path)
     list_of_image = self.ReadImage.openImage()
     for z in list_of_image:
         print min(z.Image3D), max(z.Image3D), z.sigma
Beispiel #35
0
class KeyPointOrientation(object):
    def __init__(self, path):
        self.path = path
        path_for_keypoints = path + '/Hessian3D/'
        path_for_Gaussian = path + '/3DGaussianSmoothing'
        self.ImageReader = ReadImage(path_for_Gaussian)
        self.PointReader = ReadImage(path_for_keypoints)
        self.list_with_keyponits = self.PointReader.openImage()
        self.spacing = self.list_with_keyponits[0].spacing
        self.size_in_pixels_xy = 3
        sigma_x = self.size_in_pixels_xy*1.5  # list_with_keyponits[0].sigma * 2 mask size is 9


        x_range = np.arange(0, self.size_in_pixels_xy + 1)
        self.pixel_distance_x = np.sort(np.concatenate((-x_range[1:], x_range)))
        self.size_of_window_x = self.size_in_pixels_xy
        self.size_of_window_z = self.size_in_pixels_xy
        self.X, self.Y, self.Z = np.meshgrid(self.pixel_distance_x, self.pixel_distance_x,
                                             self.pixel_distance_x)
        # self.X, self.Y = np.meshgrid(self.pixel_distance_x, self.pixel_distance_x)
        # to dla 1.5 sigmy

        self.gaussian_weight = np.exp(-((self.X ** 2 + self.Y ** 2 + self.Z ** 2) / (2 * (sigma_x / 2) ** 2)))

    def apply(self):
        list_with_GaussianImages = self.ImageReader.openImage()
        self.SaveImage = SaveImage(self.path + '/KeyPointsOrientation/')
        for i in range(0, len(self.list_with_keyponits)):
            orientation = self.keypoints_histograms(list_with_GaussianImages[i + 1], self.list_with_keyponits[i])
            list_with_GaussianImages[i + 1].keypoints_orientation = orientation
            list_with_GaussianImages[i + 1].keypoints_min = self.list_with_keyponits[i].keypoints_min
            list_with_GaussianImages[i + 1].keypoints_max = self.list_with_keyponits[i].keypoints_max
            self.SaveImage.saveImage(list_with_GaussianImages[i + 1])


    def keypoints_histograms(self, image3D_agregator, keypooints_agregator):
        # diff in [mm space]
        dx, dy, dz = np.gradient(image3D_agregator.Image3D, image3D_agregator.spacing[0], image3D_agregator.spacing[1],
                                 image3D_agregator.spacing[2])

        keypoints = keypoints_concatenate(keypooints_agregator)

        # do konfigracji
        delta_azimuth = np.pi / 4.
        delta_elevation = np.pi / 4.
        #solid_azimuth=np.arange(0,2*np.pi+delta_elevation,delta_elevation)
        #solid_angle = 1.0 / (delta_elevation * (np.cos(solid_azimuth) - np.cos(solid_azimuth + delta_azimuth)))

        #solid_angle = normalize(solid_angle, [np.min(solid_angle), np.max(solid_angle)], [0, 1])

        keypoint_list = []

        for k in range(0, keypoints.shape[0]):
            try:
                i = keypoints[k][0]
                j = keypoints[k][1]
                z = keypoints[k][2]
            except IndexError:
                keypoint_list.append([0,0,0,0,0])
                pass
                continue



            temp_x = dx[i - self.size_of_window_x:i + self.size_of_window_x + 1,
                     j - self.size_of_window_x:j + self.size_of_window_x + 1,
                     z - self.size_of_window_z:z + self.size_of_window_z + 1]

            temp_y = dy[i - self.size_of_window_x:i + self.size_of_window_x + 1,
                     j - self.size_of_window_x:j + self.size_of_window_x + 1,
                     z - self.size_of_window_z:z + self.size_of_window_z + 1]

            temp_z = dz[i - self.size_of_window_x:i + self.size_of_window_x + 1,
                     j - self.size_of_window_x:j + self.size_of_window_x + 1,
                     z - self.size_of_window_z:z + self.size_of_window_z + 1]

            if temp_x.shape[0] != 2 * self.size_in_pixels_xy + 1:  continue
            if temp_x.shape[1] != 2 * self.size_in_pixels_xy + 1:  continue
            if temp_x.shape[2] != 2 * self.size_in_pixels_xy + 1:  continue

            self.magnitude = np.sqrt(temp_x ** 2 + temp_y ** 2 + temp_z ** 2)
            self.azimuth = np.arctan2(temp_y, temp_x) + np.pi

            self.elevation = np.arctan2(temp_z,np.sqrt(temp_x ** 2 + temp_y ** 2))+np.pi/2


            self.magnitude = normalize(self.magnitude, [np.min(self.magnitude), np.max(self.magnitude)], [0, 1])

            self.gaussian_weight = normalize(self.gaussian_weight, [np.min(self.gaussian_weight),
                                                                    np.max(self.gaussian_weight)], [0, 1])

            weights = self.magnitude * self.gaussian_weight #* solid_angle
            self.weights = normalize(weights, [np.min(weights), np.max(weights)], [0, 1])

            NO_xbin = 4
            NO_ybin = 8

            H2D = Histogram2D(NO_xbin, NO_ybin)
            H2D.apply(self.elevation, self.azimuth, weights)
            #self.H2D = H2D.get_Histogram2D()
            #fig =figure()
            from mpl_toolkits.mplot3d import Axes3D
            #ax = fig.add_subplot(111,projection='3d')
            #barchart(H2D.H)

            #mlab.colorbar(nb_labels=2,label_fmt='%.1f')
            #show()
            angles = H2D.get_Histogram2D_max()
            if angles.size == 4:
                keypoint_list.append([i, j, z, angles[0][0], angles[0][1]])
                keypoint_list.append([i, j, z, angles[1][0], angles[1][1]])
            elif angles.size == 2:

                keypoint_list.append([i, j, z, angles[0][0], angles[0][1]])

        return keypoint_list
Beispiel #36
0
class ExtremaSpace3D(object):
    def __init__(self, path):
        """
        Find local extrema without edges in LoG space
        """
        self.path = path
        self.min_list = []
        self.max_list = []

        self.ReadImage = ReadImage(path)

    def find(self):
        """

        :param list_with_images_3D: list with three images as np.array after LoG in LoG space direction with increasing sigma
        :return: void
        """
        path_to_save = 'DoGSpaceExtremum3D/'
        print(self.path[:-16] + path_to_save)
        saving = SaveImage(self.path[:-16] + path_to_save)

        list_with_im = self.ReadImage.openImage()
        for i in range(1, len(list_with_im) - 1):
            self.min_list = []
            self.max_list = []
            list_with_three_images_3D = list_with_im[i - 1:i + 2]
            print(len(list_with_three_images_3D))
            min_index = list_with_im[i].keypoints_min
            max_index = list_with_im[i].keypoints_max
            print(list_with_im[i].keypoints_min.shape)
            for min_idx in min_index:
                i = min_idx[0]
                j = min_idx[1]
                z = min_idx[2]

                bool_array0 = list_with_three_images_3D[1].Image3D[
                    i, j,
                    z] > list_with_three_images_3D[0].Image3D[i - 1:i + 2,
                                                              j - 1:j + 2,
                                                              z - 1:z + 2]
                bool_array1 = list_with_three_images_3D[1].Image3D[
                    i, j,
                    z] > list_with_three_images_3D[2].Image3D[i - 1:i + 2,
                                                              j - 1:j + 2,
                                                              z - 1:z + 2]

                sum0 = np.sum(bool_array0) + np.sum(bool_array1)

                if sum0 == 0:
                    self.min_list.append(min_idx)

            for max_idx in max_index:

                i = max_idx[0]
                j = max_idx[1]
                z = max_idx[2]
                # first image in DoG space comparison
                bool_array0 = list_with_three_images_3D[1].Image3D[
                    i, j,
                    z] < list_with_three_images_3D[0].Image3D[i - 1:i + 2,
                                                              j - 1:j + 2,
                                                              z - 1:z + 2]
                # third image in DoG space comparison
                bool_array1 = list_with_three_images_3D[1].Image3D[
                    i, j,
                    z] < list_with_three_images_3D[2].Image3D[i - 1:i + 2,
                                                              j - 1:j + 2,
                                                              z - 1:z + 2]
                sum0 = np.sum(bool_array0) + np.sum(bool_array1)
                if sum0 == 0:
                    self.max_list.append(max_idx)

            min3D, max3D = self.get_min_max()
            print(min3D.shape, max3D.shape)
            temp_image = deepcopy(list_with_three_images_3D[1])
            temp_image.keypoints_min = min3D
            temp_image.keypoints_max = max3D
            saving.saveImage(temp_image)

    def get_min_max(self):
        """
        :return: list of indexes as a np.array min and max [i,j,z]
        """
        return np.array(self.min_list), np.array(self.max_list)
Beispiel #37
0
 def test_show(self):
     path = './test_data/1_nd/CT_analyses/Hessian3D/'
     list_with_images = ReadImage(path).openImage()
     for z in list_with_images:
         keypoints_vizualization(z)
Beispiel #38
0
class ExtremaSpace3D(object):
    def __init__(self, path):
        """
        Find local extrema without edges in LoG space
        """
        self.path = path
        self.min_list = []
        self.max_list = []

        self.ReadImage = ReadImage(path)


    def find(self):
        """

        :param list_with_images_3D: list with three images as np.array after LoG in LoG space direction with increasing sigma
        :return: void
        """
        path_to_save = 'DoGSpaceExtremum3D/'
        print(self.path[:-16] + path_to_save)
        saving = SaveImage(self.path[:-16] + path_to_save)

        list_with_im = self.ReadImage.openImage()
        for i in range(1, len(list_with_im)-1):
            self.min_list = []
            self.max_list = []
            list_with_three_images_3D = list_with_im[i - 1:i + 2]
            print(len(list_with_three_images_3D))
            min_index = list_with_im[i].keypoints_min
            max_index = list_with_im[i].keypoints_max
            print(list_with_im[i].keypoints_min.shape)
            for min_idx in min_index:
                i = min_idx[0]
                j = min_idx[1]
                z = min_idx[2]

                bool_array0 = list_with_three_images_3D[1].Image3D[i, j, z] > list_with_three_images_3D[0].Image3D[
                                                                              i - 1:i + 2,
                                                                              j - 1:j + 2, z - 1:z + 2]
                bool_array1 = list_with_three_images_3D[1].Image3D[i, j, z] > list_with_three_images_3D[2].Image3D[
                                                                              i - 1:i + 2,
                                                                              j - 1:j + 2, z - 1:z + 2]

                sum0 = np.sum(bool_array0) + np.sum(bool_array1)

                if sum0 == 0:
                    self.min_list.append(min_idx)

            for max_idx in max_index:

                i = max_idx[0]
                j = max_idx[1]
                z = max_idx[2]
                # first image in DoG space comparison
                bool_array0 = list_with_three_images_3D[1].Image3D[i, j, z] < list_with_three_images_3D[0].Image3D[
                                                                              i - 1:i + 2,
                                                                              j - 1:j + 2, z - 1:z + 2]
                # third image in DoG space comparison
                bool_array1 = list_with_three_images_3D[1].Image3D[i, j, z] < list_with_three_images_3D[2].Image3D[
                                                                              i - 1:i + 2,
                                                                              j - 1:j + 2, z - 1:z + 2]
                sum0 = np.sum(bool_array0) + np.sum(bool_array1)
                if sum0 == 0:
                    self.max_list.append(max_idx)

            min3D, max3D = self.get_min_max()
            print(min3D.shape,max3D.shape)
            temp_image = deepcopy(list_with_three_images_3D[1])
            temp_image.keypoints_min = min3D
            temp_image.keypoints_max = max3D
            saving.saveImage(temp_image)


    def get_min_max(self):
        """
        :return: list of indexes as a np.array min and max [i,j,z]
        """
        return np.array(self.min_list), np.array(self.max_list)