Giter Club home page Giter Club logo

Comments (3)

the-lay avatar the-lay commented on July 19, 2024

Hi @renerichter ! Great to see the interest!

Unfortunately I still haven't implemented automatic calculation of window sizes and overlap to get constant 1.0 "weight" in Merger. It is in the roadmap and I have to admit it has been there for too long! For now, you have to calculate "correct" sizes yourself and/or apply padding like in the examples/2d_overlap_tile.py.

You could divide the merged data by the number of times each element has been seen in tiles. This would work properly only for boxcar (constant) window: imf = merger.merge(unpad=True, argmax=False) / merger.data_visits[:imsize, :imsize]
I think I will add such normalization as another flag for Merger.merge() next time I work on the project.

normalize_tiler

Hope that helps!

from tiler.

renerichter avatar renerichter commented on July 19, 2024

I added #7 and would like to discuss the merging strategy.
Building onto my pull-request the following test-code is applied

Test Code

import numpy as np
from tiler import Tiler,Merger
import matplotlib.pyplot as plt

# %% Test example for online

# parameter
data_shape = [1,256,256]
tile_shape = np.array([1,64,64])
overlap=np.array([0,7,20])
tiler_mode = 'wrap'
windows_supported = ['boxcar', 'triang', 'blackman', 'hamming', 'hann', 'bartlett', 'flattop', 'parzen', 'bohman', 'blackmanharris', 'nuttall', 'barthann', 'overlap-tile']

# image
xy = np.ogrid[0:data_shape[-2],0:data_shape[-1]]
xy = np.sqrt(xy[0]*np.transpose(xy[0])+xy[1]*np.transpose(xy[1]))
im = np.cos(4*xy*np.pi/np.max(xy))[np.newaxis]
merged_images = [im,]

# tile me
tiler = Tiler(data_shape=data_shape, tile_shape=tile_shape,overlap=tuple(overlap),get_padding=True)
im_padded = tiler.pad_outer(im,tiler.pads)
weights_sums = [np.ones(im_padded.shape),]

for mwin in windows_supported:
    merger = Merger(tiler,window=mwin)
    #Merger.SUPPORTED_WINDOWS == ['boxcar', 'triang', 'blackman', 'hamming', 'hann', 'bartlett', 'flattop', 'parzen', 'bohman', 'blackmanharris', 'nuttall', 'barthann', 'overlap-tile']
    
    for tile_id, tile in tiler(im_padded):
        processed_tile = tile # lambda x: x
        merger.add(tile_id, processed_tile)

    imf = merger.merge(data_orig_shape=data_shape)
    merged_images.append(imf)
    weights_sums.append(merger.weights_sum)

# plot images
merged_images = np.array(merged_images)[:,0]
fig,ax = plt.subplots(nrows=4,ncols=4,figsize=[14,14])
plt_titles = ['reference',]+windows_supported
axm = ax.flatten()
for m,mim in enumerate(merged_images): 
    ima = axm[m].imshow(mim,interpolation='None')
    axm[m].set_title(plt_titles[m])
plt.suptitle('Resulting Images')
plt.tight_layout()
plt.show() 

# plot images
weights_sums = np.array(weights_sums)[:,0]
fig2,ax2 = plt.subplots(nrows=4,ncols=4,figsize=[14,14])
plt_titles = ['reference',]+windows_supported
axm = ax2.flatten()
inv_weights = merger.norm_by_weights((weights_sums[0])[np.newaxis], weights=weights_sums)
inv_weights/= np.max(inv_weights,axis=(-2,-1),keepdims=True)
for m,invm in enumerate(inv_weights): 
    ima = axm[m].imshow(invm**0.002,interpolation='None')
    axm[m].set_title(plt_titles[m])
plt.suptitle('Inverse Weights-maps **0.002 (for display)')
plt.tight_layout()
plt.show() 

# differences
for m,mim in enumerate(merged_images):
    print(f"All close for window_func={plt_titles[m]}?\t {np.allclose(mim,im[0])}")

The results are:

Resulting Images:

2021-09-27-09-04-21-tiler_test_res

Weights used for reweighting:

2021-09-27-09-29-05-inverse_wegihts_map

Comparison between Reference and re-merged images

All close for window_func=reference?     True
All close for window_func=boxcar?        True
All close for window_func=triang?        TrueM
All close for window_func=blackman?      True
All close for window_func=hamming?       True
All close for window_func=hann?  True
All close for window_func=bartlett?      True
All close for window_func=flattop?       False
All close for window_func=parzen?        True
All close for window_func=bohman?        True
All close for window_func=blackmanharris?        True
All close for window_func=nuttall?       True
All close for window_func=barthann?      True
All close for window_func=overlap-tile?  False

For the reweighting I interpreted the calculation steps to be like if one would calculate a center-of-mass kind of thing. Hence,

  • multiplying each tile with the window
  • summing the tiles into the final image
  • dividing by the summed weights window-function

could reproduce the wanted normalization of the output. On the other hand, if the window-functions are normed and symmetric than the final division by the weights would just undo the prior weighting of the tiles. Hence I believe I have a thinking error somehow here. What do you think?

PS: Flat-top normalization needs to be fixed...

from tiler.

the-lay avatar the-lay commented on July 19, 2024

Merged #7.
I will close this issue, but please feel free to open new issues/discussions!

from tiler.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.