def store_plotted_landmarks(closed_curve=False):
    '''
    Stores the plots of the landmarks corresponding to all the
    training samples and all the teeth in the image coordinate frame
    in seperate plots for each training sample, for each tooth.
    The scale and limits of the axes are the same for each plot.
    @param closed_curve:        must the curve be closed
    '''
    XS = l.create_full_XS()
    (ymin, ymax, xmin, xmax) = pre.learn_offsets_safe(XS)

    for j in range(XS.shape[0]):
        for i in range(XS.shape[1]):
            xCoords, yCoords = mu.extract_coordinates(XS[j, i, :])
            if (closed_curve):
                xCoords = mu.make_circular(xCoords)
                yCoords = mu.make_circular(yCoords)

            pyplot.figure()
            pyplot.title('Training sample nr: ' + str((i + 1)) + ' | ' +
                         'Tooth nr: ' + str((j + 1)))
            # x coordinates , y coordinates
            pyplot.plot(xCoords, yCoords, '-+r')
            pyplot.axis([xmin, xmax, ymin, ymax])
            pyplot.gca().set_aspect('equal', adjustable='box')
            pyplot.xlabel('x')
            pyplot.ylabel('y')
            pyplot.gca().invert_yaxis()
            fname = c.get_fname_vis_landmark((i + 1), (j + 1))
            pyplot.savefig(fname, bbox_inches='tight')
            #You get a runtime warning if you open more than 20 figures
            #Closing comes with a performance penalty
            pyplot.close()
Example #2
0
def preprocess():
    '''
    Creates XS and MS, used by the drawing functions.
        * XS contains for each tooth, for each training sample, all landmarks (in the image coordinate frame)
        * MS contains for each tooth, the tooth model (in the model coordinate frame)
    '''
    global XS, MS
    XS = l.create_full_XS()
    MS = np.zeros((c.get_nb_teeth(), c.get_nb_dim()))
    for j in range(c.get_nb_teeth()):
        M, Y = pa.PA(l.create_full_X(j+1))
        MS[j,:] = M
Example #3
0
def classify_positives(method=''):
    XS = l.create_full_XS()
    
    for s in c.get_trainingSamples_range():
        trainingSamples = c.get_trainingSamples_range()
        trainingSamples.remove(s)
        try:
            info_name_upper = c.get_dir_prefix() + 'data/Visualizations/Classified Samples/info' + method + str(s) + '-u' + '.txt' 
            info_name_lower = c.get_dir_prefix() + 'data/Visualizations/Classified Samples/info' + method + str(s) + '-l' + '.txt' 

            info_file_upper = open(info_name_upper, "w")
            info_file_lower = open(info_name_lower, "w")
            
            for i in trainingSamples:
                
                s = ''    
                if (i < 10):
                    s = '0'
                img_name = s + str(i) + '.png'
                
                min_y = min_x = float("inf")
                max_y = max_x = 0

                for j in range(0, c.get_nb_teeth()/2):
                    x_coords, y_coords = mu.extract_coordinates(XS[j, i-1, :])
                    for k in range(c.get_nb_landmarks()):
                        if x_coords[k] < min_x: min_x = x_coords[k]
                        if x_coords[k] > max_x: max_x = x_coords[k]
                        if y_coords[k] < min_y: min_y = y_coords[k]
                        if y_coords[k] > max_y: max_y = y_coords[k]
                
                line = 'rawdata/' + method + img_name + ' 1 ' + str(int(min_x - fu.offsetX)) + ' ' + str(int(min_y - fu.offsetY)) + ' ' + str(int(max_x - min_x)) + ' ' + str(int(max_y - min_y)) + '\n' 
                info_file_upper.write(line)
                
                min_y = min_x = float("inf")
                max_y = max_x = 0
                
                for j in range(c.get_nb_teeth()/2, c.get_nb_teeth()):
                    x_coords, y_coords = mu.extract_coordinates(XS[j, i-1, :])
                    for k in range(c.get_nb_landmarks()):
                        if x_coords[k] < min_x: min_x = x_coords[k]
                        if x_coords[k] > max_x: max_x = x_coords[k]
                        if y_coords[k] < min_y: min_y = y_coords[k]
                        if y_coords[k] > max_y: max_y = y_coords[k] 
                
                line = 'rawdata/' + method + img_name + ' 1 ' + str(int(min_x - fu.offsetX)) + ' ' + str(int(min_y - fu.offsetY)) + ' ' + str(int(max_x - min_x)) + ' ' + str(int(max_y - min_y)) + '\n' 
                info_file_lower.write(line) 

        finally:
            info_file_upper.close()
            info_file_lower.close()
Example #4
0
def create_individual_bboxes(method=''):
    XS = l.create_full_XS()
    IBS = np.zeros((XS.shape[0], XS.shape[1], 4))
    for j in range(XS.shape[0]):
        for i in range(XS.shape[1]):
            min_y = min_x = float("inf")
            max_y = max_x = 0
            x_coords, y_coords = mu.extract_coordinates(XS[j,i,:])
            for k in range(x_coords.shape[0]):
                if x_coords[k] < min_x: min_x = x_coords[k]
                if x_coords[k] > max_x: max_x = x_coords[k]
                if y_coords[k] < min_y: min_y = y_coords[k]
                if y_coords[k] > max_y: max_y = y_coords[k]
            IBS[j,i,0] = min_x - fu.offsetX
            IBS[j,i,1] = max_x - fu.offsetX
            IBS[j,i,2] = min_y - fu.offsetY
            IBS[j,i,3] = max_y - fu.offsetY
    return IBS 
Example #5
0
def preproccess():
    '''
    Preproccess all the radiographs.
    '''
    XS = l.create_full_XS()
    (ymin, ymax, xmin, xmax) = learn_offsets_safe(XS)
    print("Preproccess learned offsets:")
    print(" * ymin: " + str(ymin)) #ymin: 497.0
    print(" * ymax: " + str(ymax)) #ymax: 1362.0
    print(" * xmin: " + str(xmin)) #xmin: 1234.0
    print(" * xmax: " + str(xmax)) #xmax: 1773.0
    
    for i in c.get_trainingSamples_range():
        # read -> crop -> convert to grey scale
        grey_image = cv2.cvtColor(crop_by_diagonal(cv2.imread(c.get_fname_radiograph(i)), ymin, ymax, xmin, xmax), cv2.COLOR_BGR2GRAY)
        grey_image_denoised = cv2.fastNlMeansDenoising(grey_image)
        cv2.imwrite(c.get_fname_vis_pre(i, method='O'), grey_image)
        cv2.imwrite(c.get_fname_vis_pre(i, method='D'), grey_image_denoised)
        cv2.imwrite(c.get_fname_vis_pre(i, method='EH'), cv2.equalizeHist(grey_image))
        cv2.imwrite(c.get_fname_vis_pre(i, method='EHD'), cv2.equalizeHist(grey_image_denoised))
        cv2.imwrite(c.get_fname_vis_pre(i, method='SC'), stretch_contrast(grey_image))
        cv2.imwrite(c.get_fname_vis_pre(i, method='SCD'), stretch_contrast(grey_image_denoised))
Example #6
0
def create_negatives(method=''):
    XS = l.create_full_XS()
    
    for i in c.get_trainingSamples_range():
        fname = c.get_fname_vis_pre(i, method)
        img = cv2.imread(fname)
        
        s = ''    
        if (i < 10): s = '0'
        
        min_y = min_x = float("inf")
        max_y = max_x = 0
    
        for j in range(0, c.get_nb_teeth()/2):
            x_coords, y_coords = mu.extract_coordinates(XS[j, i-1, :])
            for k in range(c.get_nb_landmarks()):
                if x_coords[k] < min_x: min_x = x_coords[k]
                if x_coords[k] > max_x: max_x = x_coords[k]
                if y_coords[k] < min_y: min_y = y_coords[k]
                if y_coords[k] > max_y: max_y = y_coords[k]
        
        fname = c.get_dir_prefix() + 'data/Visualizations/Classified Samples/' + method + str(s) + str(i) + '-l' + '.png'    
        cv2.imwrite(fname, img[max_y-fu.offsetY+1:,:])
        
        min_y = min_x = float("inf")
        max_y = max_x = 0
        
        for j in range(c.get_nb_teeth()/2, c.get_nb_teeth()):
            x_coords, y_coords = mu.extract_coordinates(XS[j, i-1, :])
            for k in range(c.get_nb_landmarks()):
                if x_coords[k] < min_x: min_x = x_coords[k]
                if x_coords[k] > max_x: max_x = x_coords[k]
                if y_coords[k] < min_y: min_y = y_coords[k]
                if y_coords[k] > max_y: max_y = y_coords[k] 
        
        fname = c.get_dir_prefix() + 'data/Visualizations/Classified Samples/' + method + str(s) + str(i) + '-u' + '.png'    
        cv2.imwrite(fname, img[:min_y-fu.offsetY,:])