diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index fa4d835..5318e4a 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -35,11 +35,20 @@ jobs: password: ${{ secrets.DOCKER_PWORD }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - + + # - name: Get script version + #id: version + #run: echo "{version}=${(python mindagap.py -v)}" >> $GITHUB_STATE # This give error: bad substitution + - name: Build and push + id: docker_build uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ secrets.DOCKER_USERNAME }}/mindagap:${{github.sha}}, ${{ secrets.DOCKER_USERNAME }}/mindagap:latest + + # ${{ secrets.DOCKER_USERNAME }}/mindagap:${{steps.version.outputs.version}} + + diff --git a/Dockerfile b/Dockerfile index 923c440..d3360ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,11 @@ RUN micromamba install -y -n base -f /tmp/env.yaml && \ micromamba clean --all --yes ARG MAMBA_DOCKERFILE_ACTIVATE=1 WORKDIR /mindagap -COPY . . \ No newline at end of file +COPY . . + + +# Set a label with the version information +#ARG VERSION +#LABEL version=$VERSION + +#CMD ["python", "mindagap.py", "-v"] # Seems to give error of uninstalled library diff --git a/README.md b/README.md index 1376a14..fe3e2b2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -# MindaGap +# MindaGap + +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8120559.svg)](https://doi.org/10.5281/zenodo.8120559) + + Takes a single panorama image and fills the empty grid lines with neighbour-weighted values. Small box sizes yield limited results but work the best with a high loop number (like 40). Increase boxsize to overcome bigger gaps. @@ -76,3 +80,8 @@ docker build -t mindagap . docker run --rm -it mindagap:latest \ python /mindagap/mindagap.py ``` + + +How to cite +-------------- + Ricardo Guerreiro, Florian Wuennemann, & pvtodorov. (2023). ViriatoII/MindaGap: v0.0.3 (0.0.3). Zenodo. https://doi.org/10.5281/zenodo.8120559 diff --git a/env.yml b/env.yml index 4d1e162..85d621f 100644 --- a/env.yml +++ b/env.yml @@ -73,7 +73,9 @@ dependencies: - pip=22.3 - pixman=0.40.0 - python_abi=3.9 + - procps-ng - readline=8.1.2 + - rich - scipy=1.9.3 - setuptools=65.5.0 - six=1.16.0 diff --git a/mindagap.py b/mindagap.py index 720f2ae..2b71302 100644 --- a/mindagap.py +++ b/mindagap.py @@ -1,11 +1,10 @@ -doc = ''' USAGE: python mindagap.py --edges +doc = ''' USAGE: python mindagap.py -xt -yt --edges Takes a single panorama image and fills the empty grid lines with neighbour-weighted values. Small boxsize yields limited results but works the best with a high loop number (like 20) Increase boxsize to overcome bigger gaps - - is optional parameter to deal with adjacent tiles without gaps but where there are visible different exposures (EXPERIMENTAL) + is optional parameter to deal with adjacent tiles without gaps but where there are visible different exposures (EXPERIMENTAL) --edges is optional parameter to blur area around grid, for smoother transitions between tiles with different exposures (EXPERIMENTAL) @@ -58,9 +57,12 @@ def fill_grids(img_array, box_size = 5, nloops = 1, edges = 0, Xtilesize = None) for xjump in range(Xtilesize, panoXmax, Xtilesize): xmin,xmax = xjump -1 ,xjump + 2 grid_coords [:,xmin:xmax] = True + print("Test 2") + if edges > 0: # Kernel: here you should define how much the True "dilates" + expansion = np.array([[True] *edges] *edges) # Expand/dilate grid (https://python.tutorialink.com/how-to-expand-dilate-a-numpy-array/) @@ -69,11 +71,10 @@ def fill_grids(img_array, box_size = 5, nloops = 1, edges = 0, Xtilesize = None) expansion.astype(int), mode='same').astype(bool) # Create a blurred image and replace original grid positions by new blur value. Iterate - for i in range(nloops): + for i in track(range(nloops),description='[green]Applying Gaussian Blur to gridlines ...'): # Smooth edges as well (last loops only) if asked if edges and (i > nloops -5): - #blur_img = cv2.GaussianBlur(im_copy,(box_size,box_size), 0) blur_img = cv2.medianBlur(im_copy,box_size,cv2.BORDER_DEFAULT) im_copy[expanded_grid] = blur_img[expanded_grid] @@ -92,6 +93,7 @@ def fill_grids(img_array, box_size = 5, nloops = 1, edges = 0, Xtilesize = None) from scipy.signal import convolve2d import numpy as np import matplotlib.pyplot as plt + from rich.progress import track #increase max allowed image size os.environ["OPENCV_IO_MAX_IMAGE_PIXELS"] = pow(2,40).__str__() @@ -106,9 +108,10 @@ def fill_grids(img_array, box_size = 5, nloops = 1, edges = 0, Xtilesize = None) parser.add_argument("-r", "--rounds", nargs = '?', type=int, default = 40, help="Number of rounds to apply gaussianBlur (more is better)") parser.add_argument("-xt", "--Xtilesize", nargs = '?', type=int, default = None, help="Tile size (distance between gridlines) on X axis") parser.add_argument("-yt", "--Ytilesize", nargs = '?', type=int, default = None, help="Tile size (distance between gridlines) on Y axis") + parser.add_argument("-e", '--edges', nargs = '?', default = 0, help="Also smooth edges near grid lines") - parser.add_argument("-v", '--version', action='store_true', default = False, help="Print version number.") - args=parser.parse_args() + parser.add_argument("-v", '--version', action='store_true', default = False, help="Print version number.") args=parser.parse_args() + if args.sizekernel % 2 == 0: print("-s argument must be uneven number") ; exit() @@ -129,20 +132,26 @@ def fill_grids(img_array, box_size = 5, nloops = 1, edges = 0, Xtilesize = None) # Read input as tif file or as png/jpg img = read_img(args.input) panoYmax,panoXmax = img.shape [-2:] + + print("Test 1") # Apply fill_grids function and write to file ##### # Work on composite images or z-layered tiffs if len(img.shape) > 2: layers = [] for l in range(img.shape[0]): + layers.append(fill_grids(img_array=img[l,:,:], box_size = args.sizekernel, nloops= args.rounds, edges = args.edges)) img = np.array(layers ) else: # Work on 2D images + img = fill_grids(img_array=img, box_size = args.sizekernel, nloops= args.rounds, edges = args.edges) + # Save as tif file or as png/ + #cv2.imwrite(pathname + '_gridfilled' + extension, img) if 'tif' in extension: