# -*- coding: utf-8 -*- """ GEPARD - Gepard-Enabled PARticle Detection Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für Polymerforschung Dresden e. V. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program, see COPYING. If not, see . """ import cv2 import numpy as np def imageStacking(colimgs): full = [] images = [] laplacians = [] for img in colimgs: gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) lap = cv2.Laplacian(gray, cv2.CV_64F) full.append(img) images.append(gray) blurlap = (cv2.GaussianBlur((lap)**2,(25,25),0)) laplacians.append(blurlap) images = np.array(images) laplacians = np.array(laplacians) full = np.array(full) full = np.uint8(full) lap = laplacians+.1 zval = lap.argmax(axis=0)*(255./(lap.shape[0] - (1 if lap.shape[0]>1 else 0))) im = np.sum(full * lap[:,:,:,np.newaxis], axis=0)/(lap[:,:,:,np.newaxis].sum(axis=0)) zval = np.uint8(zval) im = np.uint8(im) return im, zval def combineImages(path, nx, ny, nk, width, height, angle): full = None for i in range(nx): for j in range(ny): if nk > 1: colimgs = [] for k in range(nk): colimgs.append(cv2.imread(path + f'test_{i}_{j}_{k}.bmp')) img = imageStacking(colimgs) else: img = cv2.imread(path + f'test_{i}_{j}_1.bmp') dx = i*.9*img.shape[1] dy = j*.8*img.shape[0] c, s = np.cos(np.radians(angle)), np.sin(np.radians(angle)) M = np.float32([[c,s,dx],[-s,c,dy]]) dst = cv2.warpAffine(img, M, (int(img.shape[1]*((nx-1)*.9 +1)), int(img.shape[0]*((ny-1)*.8 +1)))) if full is None: full = dst else: full = cv2.max(full,dst) cv2.imwrite("full_dunkel.png", full) if __name__ == "__main__": path = "../Bildserie-Scan/dunkelfeld/" Nx, Ny, Nk = 10, 10, 4 width, height, angle = 463.78607177734375, 296.0336608886719, -0.04330849274992943 combineImages(path, Nx, Ny, Nk, width, height, angle)