def openImageDialog(self):
        filename = QFileDialog.getOpenFileName(
            self, "Open file", None, 'Image Files (*.png *.jpg *.bmp)')

        if filename[0]:
            # Read the image
            self.imageSrc = image_read(filename[0])

            # Compute the Max-Tree
            (self.maxtree_p,
             self.maxtree_s) = maxtree_union_find_level_compression(
                 self.imageSrc, connection8=True)

            self.imageSrcFlat = self.imageSrc.flatten()
            self.maxtree_a = compute_attribute_area(self.maxtree_s,
                                                    self.maxtree_p,
                                                    self.imageSrcFlat)

            # Update slider and spinbox in the image resolution range
            self.areaThresholdSlider.setRange(
                0, (self.imageSrc.shape[0] * self.imageSrc.shape[1]))
            self.areaThresholdSpinbox.setRange(
                0, (self.imageSrc.shape[0] * self.imageSrc.shape[1]))

            # Update the image label
            self.updateImages()
Example #2
0
    def cam(self):
        img_size = self.flag.image_size
        batch_size = self.flag.batch_size
        epochs = self.flag.total_epoch

        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        set_session(tf.Session(config=config))

        with open(os.path.join(self.flag.ckpt_dir, self.flag.ckpt_name, 'model.json'), 'r') as json_file:
            loaded_model_json = json_file.read()
        
        #model = model_from_json(loaded_model_json)
        model = models.vgg_like(self.flag)

        weight_list = sorted(glob(os.path.join(self.flag.ckpt_dir, self.flag.ckpt_name, 'weight*')))
        model.load_weights(weight_list[-1])
        print '[*] model load : %s'%weight_list[-1]
        
        label_list = [os.path.basename(path) for path 
                    in sorted(glob(os.path.join(self.flag.data_path, '*')))]
        dict_name_list = dict()
        for name in label_list:
            dict_name_list[name] = [path for path 
                    in sorted(glob(os.path.join(self.flag.data_path, name, '*')))]
            dict_name_list[name] = dict_name_list[name][:50]
        
        data_list = []
        [data_list.append(image_read(name, color_mode=1, target_size=128)) 
                for name in dict_name_list['dog']]
        # print len(data_list)
        np_Inference_data_list = np.array(data_list)[:,0,:,:,:]
        np_original_data_list = np.array(data_list)[:,1,:,:,:].astype(np.uint8)
        # print np_Inference_data_list.shape

        result = model.predict(np_Inference_data_list, self.flag.batch_size)
        # print result.shape
        prediction_labels = np.argmax(result, axis=1)

        classmap = get_classmap_keras(self.flag, model, np_Inference_data_list, prediction_labels)

        assert classmap.shape[0] == np_original_data_list.shape[0] == prediction_labels.shape[0]
        
        cv2.namedWindow("show", 0)
        cv2.resizeWindow("show", 500, 500)
        
        for idx in range(classmap.shape[0]):
            predicted_label = prediction_labels[idx]
            print "[*] %d's label : %s"%(idx, label_list[predicted_label])
            img_original = np_original_data_list[idx,:,:,:]
            img_classmap = classmap[idx,:,:,predicted_label]
            color_classmap = cv2.applyColorMap(img_classmap, cv2.COLORMAP_JET)
            img_show = cv2.addWeighted(img_original, 0.8, color_classmap, 0.5, 0.)
            # cv2.imshow("show", img_show)
            # cv2.imwrite("./result/dog_%d.png"%idx, img_show)
            # if cv2.waitKey(1) == 27:
            #     break
        print "[*] done"
Example #3
0
    def openImageDialog(self):
        filename = QFileDialog.getOpenFileName(
            self, "Open file", None, 'Image Files (*.png *.jpg *.bmp)')

        if filename[0]:
            # Read the image
            self.imageSrc = image_read(filename[0])
            self.maxtree = maxtree(self.imageSrc)

            # Update slider and spinbox in the image resolution range
            self.areaThresholdSlider.setRange(
                0, (self.imageSrc.shape[0] * self.imageSrc.shape[1]))
            self.areaThresholdSpinbox.setRange(
                0, (self.imageSrc.shape[0] * self.imageSrc.shape[1]))

            # Update the image label
            self.updateImages()
Example #4
0
import sys
import time
import matplotlib.pyplot as plt
import numpy as np
from utils import image_read
from maxtree import maxtree_berger, maxtree_berger_rank, maxtree_union_find_level_compression, compute_attribute_area, direct_filter

file_path = sys.argv[1]
area_filter = int(sys.argv[2])

img1 = image_read(filename=file_path)
print("Resolution: {}".format(img1.shape[0] * img1.shape[1]))
print("{}x{}".format(img1.shape[0], img1.shape[1]))

flatten_image = img1.flatten()

# Original image
fig, (fig1, fig2, fig3, fig4) = plt.subplots(1, 4)
fig1.set_axis_off()
fig2.set_axis_off()
fig3.set_axis_off()
fig4.set_axis_off()
fig1.set_title("Original")
fig1.imshow(img1, cmap="gray")

# Algorithms
start = time.time()
(parents, s) = maxtree_berger(img1, connection8=True)
end = time.time()
attr = compute_attribute_area(s, parents, flatten_image)
out1 = direct_filter(s, parents, flatten_image, attr, area_filter)
Example #5
0
import tree_of_shape
"""
I. Max-Tree
"""

#image_input = image_read("examples/images/circuit_small_small.png")
#image_output = max_tree.area_filter(image_input, 100)

#plt.imshow(image_input, cmap="gray")
#plt.show()
#plt.imshow(image_output, cmap="gray")
#plt.show()
"""
II. Tree of shapes
"""

image_input = image_read("examples/images/circuit_small_small.png")
plt.imshow(image_input, cmap="gray")
plt.show()

image_output = tree_of_shape.area_filter(image_input, 5)
plt.imshow(image_output, cmap="gray")
plt.show()

image_output = tree_of_shape.area_filter(image_input, 20)
plt.imshow(image_output, cmap="gray")
plt.show()
"""
III. Binary partition tree
"""