Exemplo n.º 1
0
def run_code(num_points, ratio, sigma, smallest_number, name=''):
    original_gaussian_cac = CACSegmenter(OriginalGaussianCAC)
    new_parameters = {
        'num_points': [num_points],
        'ratio': [ratio],
    }
    original_gaussian_cac.parameters = new_parameters
    original_gaussian_cac.sigma = sigma
    parameter_list = original_gaussian_cac.get_parameters()
    dataset = original_gaussian_cac.load_dataset('AlpertGBB07_input_subtest.txt')
    results_folder = 'segment_alpert_old_gaussian/' + original_gaussian_cac.CAC.__name__ + name + '/'
    print results_folder
    original_gaussian_cac.test_model(dataset, parameter_list[0], results_folder, plot_evolution=False)
Exemplo n.º 2
0
def run_code(num_points, ratio, sigma, smallest_number, name=''):
    original_gaussian = CACSegmenter(MultivariateGaussianCAC)
    new_parameters = {
        'num_points': [num_points],
        'ratio': [ratio],
        'smallest_number': [smallest_number]
    }
    original_gaussian.parameters = new_parameters
    original_gaussian.sigma = sigma
    parameter_list = original_gaussian.get_parameters()
    dataset = original_gaussian.load_dataset('AlpertGBB07_input_subtest.txt')
    results_folder = 'segment_alpert_multivariat_gauss/' + original_gaussian.CAC.__name__ + name + '/'
    print results_folder
    original_gaussian.test_model(dataset,
                                 parameter_list[0],
                                 results_folder,
                                 plot_evolution=False)
Exemplo n.º 3
0
                            current_cage_obj,
                            alpha,
                            grad_k,
                            color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord,
                                 self.image_obj.image,
                                 points=current_cage_obj.cage,
                                 color=color,
                                 points2=current_cage_obj.cage -
                                 alpha * 10 * grad_k)


if __name__ == '__main__':
    input_filename = 'AlpertGBB07_input_subtest.txt'
    output_folder = 'seg_im/'
    multi_mixture_gaussian_gray_cac = CACSegmenter(MultiMixtureGaussianCAC)
    new_parameters = {
        'num_points': [20],
        'ratio': [1.1],
        'smallest_number': [np.exp(-200)],
    }
    multi_mixture_gaussian_gray_cac.parameters = new_parameters
    multi_mixture_gaussian_gray_cac.sigma = 0.25
    parameter_list = multi_mixture_gaussian_gray_cac.get_parameters()

    dataset = multi_mixture_gaussian_gray_cac.load_dataset(input_filename)
    results_folder = output_folder + multi_mixture_gaussian_gray_cac.CAC.__name__ + '/'
    multi_mixture_gaussian_gray_cac.test_model(dataset,
                                               parameter_list[0],
                                               results_folder,
                                               plot_evolution=True)
Exemplo n.º 4
0
        image = self.image_obj.gray_image
        image_gradient = np.array(np.gradient(image))

        # Calculate Energy:
        omega_1 = g_energies.grad_gauss_energy_per_region(omega1_coord, affine_omega_1_coord, image, image_gradient)
        omega_2 = g_energies.grad_gauss_energy_per_region(omega2_coord, affine_omega_2_coord, image, image_gradient)
        energy = omega_1 + omega_2
        return energy

    def _plotContourOnImage(self, contour_coord, cage_obj, alpha, grad_k, color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord, self.image_obj.gray_image, points=cage_obj.cage, color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)


if __name__ == '__main__':
    input_filename = 'synthetic_locality_input.txt'
    output_folder = 'experiment1/'
    original_gaussian_gray_cac = CACSegmenter(OriginalGaussianCAC)
    parameter_list = original_gaussian_gray_cac.get_parameters()
    new_parameters = {
        'num_points': [12],
        'ratio': [1.05],
    }
    original_gaussian_gray_cac.parameters = new_parameters
    original_gaussian_gray_cac.sigma = 0.5

    parameter_list = original_gaussian_gray_cac.get_parameters()
    dataset = original_gaussian_gray_cac.load_dataset(input_filename)
    results_folder = output_folder + original_gaussian_gray_cac.CAC.__name__ + '/'
    original_gaussian_gray_cac.test_model(dataset, parameter_list[0], results_folder, plot_evolution=True)
Exemplo n.º 5
0
                                                                    self.outside_seed_mean)
        return grad_energy_1 + grad_energy_2

    def _plotContourOnImage(self, contour_coord, cage_obj, alpha, grad_k, color=[0., 0., 255.]):
        # hsi_image[:, :, 0] / (2 * 3.14) * 255.
        utils.plotContourOnImage(contour_coord, self.image_obj.image,
                                 points=cage_obj.cage,
                                 color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)
        # self.image_obj.plot_hsi_image()


if __name__ == '__main__':
    input_filename = 'BSDS300_input.txt'
    output_folder = 'seg_im/'
    color_cac = CACSegmenter(HueMeanSeedCAC)
    parameter_list = color_cac.get_parameters()
    new_parameters = {
        'num_points': [12],
        'ratio': [1.05],
        'smallest_number': [np.exp(-200)],
    }
    color_cac.parameters = new_parameters
    color_cac.sigma = 0.25
    parameter_list = color_cac.get_parameters()



    dataset = color_cac.load_dataset(input_filename)
    results_folder = output_folder + color_cac.CAC.__name__+ '/'
    color_cac.test_model(dataset, parameter_list[0], results_folder, plot_evolution=True)
            omega2_coord, affine_omega_2_coord, self.outside_gmm, image,
            image_gradient)
        energy = omega_1 + omega_2
        return energy

    def _plotContourOnImage(self,
                            contour_coord,
                            cage_obj,
                            alpha,
                            grad_k,
                            color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord,
                                 self.image_obj.image,
                                 points=cage_obj.cage,
                                 color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)


if __name__ == '__main__':
    input_filename = 'synthetic_input.txt'
    output_folder = 'other/'
    multivariate_gaussian_gray_cac = CACSegmenter(MultivariateGaussianCAC)
    parameter_list = multivariate_gaussian_gray_cac.get_parameters()

    dataset = multivariate_gaussian_gray_cac.load_dataset(input_filename)
    results_folder = output_folder + multivariate_gaussian_gray_cac.CAC.__name__ + '/'
    multivariate_gaussian_gray_cac.test_model(dataset,
                                              parameter_list[0],
                                              results_folder,
                                              plot_evolution=True)
Exemplo n.º 7
0
        image = self.image_obj.gray_image
        image_gradient = np.array(np.gradient(image))

        # Calculate Energy:
        omega_1 = mean_energy.mean_energy_grad_per_region(omega1_coord, affine_omega_1_coord, image, image_gradient)
        omega_2 = mean_energy.mean_energy_grad_per_region(omega2_coord, affine_omega_2_coord, image, image_gradient)
        energy = omega_1 + omega_2
        return energy

    def _plotContourOnImage(self, contour_coord, cage_obj, alpha, grad_k, color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord, self.image_obj.gray_image, points=cage_obj.cage, color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)


if __name__ == '__main__':
    input_filename = 'morphing_fruits_input.txt'
    output_folder = 'segment_morphing_fruits/'
    mean_gray_cac = CACSegmenter(MeanCAC)
    new_parameters = {
        'num_points': [10],
        'ratio': [1.05],
    }
    mean_gray_cac.parameters = new_parameters
    mean_gray_cac.sigma = 0.1
    parameter_list = mean_gray_cac.get_parameters()
    save_resulting_mask = '../../morphed_mask/'

    dataset = mean_gray_cac.load_dataset(input_filename)
    results_folder = output_folder + mean_gray_cac.CAC.__name__ + '/'
    mean_gray_cac.test_model(dataset, parameter_list[0], results_folder, plot_evolution=True)
Exemplo n.º 8
0
            omega_2_coord, affine_omega_2_coord, self.image_obj)
        return grad_energy_1 + grad_energy_2

    def _plotContourOnImage(self,
                            contour_coord,
                            cage_obj,
                            alpha,
                            grad_k,
                            color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord,
                                 self.image_obj.hsi_image[:, :, 0] /
                                 (2 * 3.14) * 255.,
                                 points=cage_obj.cage,
                                 color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)
        # self.image_obj.plot_hsi_image()


if __name__ == '__main__':
    input_filename = 'AlpertGBB07_input.txt'
    output_folder = 'segment_results_alpert_3/'
    color_cac = CACSegmenter(HueMeanCAC)
    parameter_list = color_cac.get_parameters()
    parameter_list = color_cac.get_parameters()
    dataset = color_cac.load_dataset(input_filename)
    results_folder = output_folder + color_cac.CAC.__name__ + '/'
    color_cac.test_model(dataset,
                         parameter_list[0],
                         results_folder,
                         plot_evolution=True)
Exemplo n.º 9
0
            grad_energy = grad_energy_1 + grad_energy_2
            total_grad_energy.append(w * grad_energy)
        return sum(total_grad_energy)

    def _plotContourOnImage(self,
                            contour_coord,
                            cage_obj,
                            alpha,
                            grad_k,
                            color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord,
                                 self.image_obj.image,
                                 points=cage_obj.cage,
                                 color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)


if __name__ == '__main__':
    input_filename = 'AlpertGBB07_input.txt'
    output_folder = 'segment_results_alpert_4/'
    rgb_cac = CACSegmenter(MeanMultiCAC,
                           type=['N', 'N', 'N'],
                           weight=[0, 0, 1])
    parameter_list = rgb_cac.get_parameters()
    dataset = rgb_cac.load_dataset(input_filename)
    results_folder = output_folder + rgb_cac.CAC.__name__ + '/'
    rgb_cac.test_model(dataset,
                       parameter_list[0],
                       results_folder,
                       plot_evolution=True)
        energy = (omega_1 + omega_2) / 2.
        return energy

    def energy_gradient(self, omega1_coord, omega2_coord, affine_omega_1_coord, affine_omega_2_coord):
        # Calculate Image gradient
        image = self.image_obj.image
        image_gradient = np.array([np.array(np.gradient(image[:, :, slice])) for slice in xrange(image.shape[2])])
        image_gradient = np.transpose(image_gradient, (1,2,3,0))
        # Calculate Energy:
        omega_1 = g_energies.grad_gauss_energy_per_region(omega1_coord, affine_omega_1_coord, self.inside_gmm, image,
                                                          image_gradient)
        omega_2 = g_energies.grad_gauss_energy_per_region(omega2_coord, affine_omega_2_coord, self.outside_gmm, image,
                                                          image_gradient)
        energy = omega_1 + omega_2
        return energy

    def _plotContourOnImage(self, contour_coord, cage_obj, alpha, grad_k, color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord, self.image_obj.image, points=cage_obj.cage, color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)


if __name__ == '__main__':
    input_filename = 'synthetic_input.txt'
    output_folder = 'other/'
    multivariate_gaussian_gray_cac = CACSegmenter(MultivariateGaussianCAC)
    parameter_list = multivariate_gaussian_gray_cac.get_parameters()

    dataset = multivariate_gaussian_gray_cac.load_dataset(input_filename)
    results_folder = output_folder + multivariate_gaussian_gray_cac.CAC.__name__ +'/'
    multivariate_gaussian_gray_cac.test_model(dataset, parameter_list[0], results_folder, plot_evolution=True)
Exemplo n.º 11
0
            energy = (omega_1 + omega_2) / float(2)
            total_energy.append(w * energy)
        return sum(total_energy)

    def energy_gradient(self, omega_1_coord, omega_2_coord, affine_omega_1_coord, affine_omega_2_coord):
        total_grad_energy = []
        for slice, (t, w) in enumerate(zip(self.type, self.weight)):
            grad_energy_1 = multi_mean_energy.generic_grad_mean_energy_per_region(omega_1_coord, affine_omega_1_coord,
                                                                                  self.image_obj, t,
                                                                                  slice)
            grad_energy_2 = multi_mean_energy.generic_grad_mean_energy_per_region(omega_2_coord, affine_omega_2_coord,
                                                                                  self.image_obj, t,
                                                                                  slice)
            grad_energy = grad_energy_1 + grad_energy_2
            total_grad_energy.append(w * grad_energy)
        return sum(total_grad_energy)

    def _plotContourOnImage(self, contour_coord, cage_obj, alpha, grad_k, color=[0., 0., 255.]):
        utils.plotContourOnImage(contour_coord, self.image_obj.image, points=cage_obj.cage, color=color,
                                 points2=cage_obj.cage - alpha * 10 * grad_k)


if __name__ == '__main__':
    input_filename = 'AlpertGBB07_input.txt'
    output_folder = 'segment_results_alpert_4/'
    rgb_cac = CACSegmenter(MeanMultiCAC, type=['N', 'N', 'N'], weight=[0, 0, 1])
    parameter_list = rgb_cac.get_parameters()
    dataset = rgb_cac.load_dataset(input_filename)
    results_folder = output_folder + rgb_cac.CAC.__name__ + '/'
    rgb_cac.test_model(dataset, parameter_list[0], results_folder, plot_evolution=True)