def get(self): #master_image = db.get(self.request.get("img_id")) master_image = open("img.jpg").read() # Create block for all items in DB blocks = [ ImageBlock(img.data) for img in ImageModel.all() ] mosaic = Mosaic(master_image, blocks) image_out = mosaic.get_image() self.response.headers['Content-Type'] = "image/png" self.response.out.write(image_out)
class mosaicTestCase(unittest.TestCase): """Test cases for EnhancedMosaic.""" def setUp(self): """Set up.""" self.mosaic = Mosaic('./dali') def tearDown(self): """Clean up.""" self.mosaic = None def testCreateMosaic(self): """Test creating a fractal mosaic.""" self.mosaic.create_mosaic('./karan.jpg', MIN_SIZE) self.mosaic.save_as('./output.jpeg')
def save_as(self, filename): '''Create and store a photomosaic version of the single picture specified by filename.''' Mosaic.save_as(self, filename)
def __init__(self, path): '''Create contents of FractalMosaic object, storing a picture database indicated by path.''' Mosaic.__init__(self, path)
def setUp(self): """Set up.""" self.mosaic = Mosaic('./dali')
print("img1 size:{}".format(img1.size)) img1.show() print("img2 size:{}".format(img2.size)) img2.show() dx = dy = 0 dt = 0.0 r = 1.0 # 時間測定開始 start = time.time() print('start') # 照合(別ファイル) dx, dy, dt, r = Mosaic.mosaic(img1, img2, r) # 時間測定終了 elapsed_time = time.time() - start print("dx:{}, dy:{}, dt:{} r:{}".format(dx, dy, dt, r)) print("time:{}".format(elapsed_time)) print('end') image3 = Pnm.construct_image(img1, img2, dx, dy, dt, 1.0) # 表示 image3.show() # 書き出し # image3.save('')
path1 = "/Users/liumeiyu/Downloads/IMG_7575.JPG" path2 = "/Users/liumeiyu/Downloads/test1.jpg" path3 = "/Users/liumeiyu/Downloads/test2.jpg" A = Histogram(path1) B = Smooth(path1) C = Change(path1) D = Base(path1) E = Binary(path1) F = D_E(path1) G = Warp(path1) H = Cvt(path1) K = Edge_detection(path1) L = Segmentation(path1) M = Mosaic(path3) N = Sampling(path1) P = Fusion(path1) # A.img_histogram_trans() # A.img_histogram() # B.linear_smooth_np() # B.linear_smooth() # B.box_smooth() # B.gaussian_smooth() # B.median_smooth() # B.median_smooth_x(5) # C.fft_high_change(60) # C.change_cv()
def _ee_image(self): logging.debug('Creating mosaic of ' + str(self)) return Mosaic(self).create(self._data_sets())
def test_speed_mosaic(): m = Mosaic("dali") m.create_mosaic("karan.jpg", 10) m.save_as("karan_mosaic.jpg")
def start_btn_cb(self): if self.errors(): exit() img_h = int(self.img_h.get()) img_w = int(self.img_w.get()) tile_val = int(self.tile_size.get()) dis_metric = self.hist_var.get() filename = self.image_path[self.image_path.rfind("/") + 1:-4] filename_out = filename + time.strftime("%Y%m%d-%H-%M-%S") + \ "-" + dis_metric + "-" + str(tile_val) + "-" + \ str(img_w) + "x" + str(img_h) mos = Mosaic(self.image_path, (img_w, img_h), tile_val, dis_metric, filename_out) if self.part_chooser.get() == "A": if self.src_dir is None: print("Select source directory") exit() mos.read_src_images(self.src_dir) mos.create_mosaic(self.src_dir) elif self.part_chooser.get() == "C": dir = mos.classify_img() mos.read_src_images(dir) mos.create_mosaic(dir)
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.setFixedSize(660, 500) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.comboBox_grid = QtWidgets.QComboBox(self.centralwidget) self.comboBox_grid.setGeometry(QtCore.QRect(540, 330, 86, 25)) self.comboBox_grid.setObjectName("comboBox_grid") self.comboBox_grid.addItem("") self.comboBox_grid.addItem("") self.comboBox_grid.addItem("") self.comboBox_grid.addItem("") self.comboBox_grid.addItem("") self.comboBox_grid.addItem("") self.comboBox_grid.addItem("") self.comboBox_grid.hide() self.pushButton_start = QtWidgets.QPushButton(self.centralwidget) self.pushButton_start.setGeometry(QtCore.QRect(540, 410, 89, 25)) self.pushButton_start.setObjectName("pushButton_start") self.pushButton_start.hide() self.label_grid = QtWidgets.QLabel(self.centralwidget) self.label_grid.setGeometry(QtCore.QRect(480, 330, 51, 21)) self.label_grid.setFrameShape(QtWidgets.QFrame.NoFrame) self.label_grid.setObjectName("label_grid") self.label_grid.hide() self.progressBar = QtWidgets.QProgressBar(self.centralwidget) self.progressBar.setGeometry(QtCore.QRect(20, 410, 361, 23)) self.progressBar.setObjectName("progressBar") self.progressBar.setProperty("value", 0) self.progressBar.hide() self.image = QtWidgets.QLabel(self.centralwidget) self.image.setGeometry(QtCore.QRect(20, 20, 300, 300)) self.image.setText("") self.image.setScaledContents(True) self.image.setObjectName("image") self.mozaika = QtWidgets.QLabel(self.centralwidget) self.mozaika.setGeometry(QtCore.QRect(340, 20, 300, 300)) self.mozaika.setText("") self.mozaika.setScaledContents(True) self.mozaika.setObjectName("mozaika") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 505, 22)) self.menubar.setObjectName("menubar") self.menuPlik = QtWidgets.QMenu(self.menubar) self.menuPlik.setObjectName("menuPlik") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.action_load_path = QtWidgets.QAction(MainWindow) self.action_load_path.setObjectName("action_load_path") self.action_load_img = QtWidgets.QAction(MainWindow) self.action_load_img.setObjectName("action_load_img") self.action_save_img = QtWidgets.QAction(MainWindow) self.action_save_img.setObjectName("action_save_img") self.action_save_img.setEnabled(False) self.menuPlik.addAction(self.action_load_path) self.menuPlik.addAction(self.action_load_img) self.menuPlik.addAction(self.action_save_img) self.menubar.addAction(self.menuPlik.menuAction()) self.pushButton_start.clicked.connect(self.start) self.action_load_img.triggered.connect(self.load_image) self.action_load_path.triggered.connect(self.load_path) self.action_save_img.triggered.connect(self.save_image) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Mosaicapp")) self.comboBox_grid.setItemText(0, _translate("MainWindow", "8x8")) self.comboBox_grid.setItemText(1, _translate("MainWindow", "20x20")) self.comboBox_grid.setItemText(2, _translate("MainWindow", "40x40")) self.comboBox_grid.setItemText(3, _translate("MainWindow", "80x80")) self.comboBox_grid.setItemText(4, _translate("MainWindow", "100x100")) self.comboBox_grid.setItemText(5, _translate("MainWindow", "200x200")) self.comboBox_grid.setItemText(6, _translate("MainWindow", "400x400")) self.pushButton_start.setText(_translate("MainWindow", "Start")) self.label_grid.setText(_translate("MainWindow", "Grid:")) self.menuPlik.setTitle(_translate("MainWindow", "File")) self.action_load_path.setText(_translate("MainWindow", "Load gallery path")) self.action_load_img.setText(_translate("MainWindow", "Load image")) self.action_save_img.setText(_translate("MainWindow", "Save image")) def start(self): self.msc = Mosaic() self.msc.im = self.img_file self.msc.path = self.path self.msc.grid = self.get_grid() self.progressBar.show() self.new_image = self.msc.make_mosaic(self.progressBar) self.mozaika.setPixmap(QtGui.QPixmap('temporary_img.jpg')) os.remove('temporary_img.jpg') self.action_save_img.setEnabled(True) def load_image(self): self.img = QFileDialog.getOpenFileName() self.img_file = Image.open(self.img[0]) self.image.setPixmap(QtGui.QPixmap(self.img[0])) self.pushButton_start.show() self.label_grid.show() self.comboBox_grid.show() def load_path(self): self.path = QFileDialog.getExistingDirectory() def get_grid(self) -> int: self.grid = int(self.comboBox_grid.currentText().split('x')[0]) return self.grid def save_image(self): self.w = Widget() self.w.get_mosaic_img(self.new_image)
def start_btn_cb(self): if self.errors(): exit() img_h = int(self.img_h.get()) img_w = int(self.img_w.get()) tile_val = int(self.tile_size.get()) dis_metric = self.hist_var.get() filename = self.image_path[self.image_path.rfind("/") + 1:-4] filename_out = filename + time.strftime( "%Y%m%d-%H-%M-%S") + "-" + dis_metric + "-" + str( tile_val) + "-" + str(img_w) + "x" + str(img_h) mos = Mosaic(self.image_path, (img_w, img_h), tile_val, self.src_dir, dis_metric, filename_out) if self.part_chooser.get() == "A": mos.read_src_images() mos.create_mosaic() elif self.part_chooser.get() == "C": mos.compute_partB() mos.update_src_images() mos.read_src_images() mos.create_mosaic()
arg_parser.add_argument('-y', dest='y', type=int, help='Mosaic thumbnail tile Y dimension') arg_parser.add_argument('-o', dest='output_file', type=str, required=True, help='Mosaic output image name') args = arg_parser.parse_args() # mosaic creation constructs dimensions = (args.x or args.thumb_size, args.y or args.thumb_size) image_mapper = ImageMapper() mosaic_builder = Mosaic() pixel_analyzer = PixelAnalyzer() image_retriever = ImageRetrievalFactory.construct(args.source_type, dimensions, args.input_file) image_library = ImageLibrary() print("Parsing source image...") mosaic = mosaic_builder.tile(image_mapper.read_pixels(args.input_file), dimensions) if args.source_type == ImageRetrievalFactory.RETRIEVE_LIBRARY: print("Loading image library...") image_retriever.load_library(image_library) print("Generating photomosaic...") for i in range(0, len(mosaic)):
def test_speed_mosaic(): m = Mosaic('dali') m.create_mosaic('karan.jpg', 10) m.save_as('karan_mosaic.jpg')