Skip to content

Commit

Permalink
merge V03 with V04
Browse files Browse the repository at this point in the history
  • Loading branch information
guerrer committed Jan 30, 2024
2 parents dedfb6b + d44d394 commit db38355
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}


9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions mindagap.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
doc = ''' USAGE: python mindagap.py <PANORAMA.tif> <boxsize> <loopnum> <tilesize> --edges <True|False>
doc = ''' USAGE: python mindagap.py <PANORAMA.tif> <boxsize> <loopnum> -xt <Xtilesize> -yt <Ytilesize> --edges <True|False>
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
<tilesize> is optional parameter to deal with adjacent tiles without gaps but where there are visible different exposures (EXPERIMENTAL)
<tilesize> 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)
Expand Down Expand Up @@ -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/)
Expand All @@ -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]

Expand All @@ -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__()
Expand All @@ -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()
Expand All @@ -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:
Expand Down

0 comments on commit db38355

Please sign in to comment.