Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kvdomingo committed May 6, 2022
0 parents commit 5542b4b
Show file tree
Hide file tree
Showing 7 changed files with 848 additions and 0 deletions.
142 changes: 142 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
.idea/

### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

1 change: 1 addition & 0 deletions deweave/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
57 changes: 57 additions & 0 deletions deweave/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import sys
import numpy as np
import cv2 as cv
import scipy.fftpack as fft
from pathlib import Path
from matplotlib import pyplot as plt

plt.rcParams.update(
{
"figure.figsize": (7, 7),
"figure.dpi": 150,
"font.family": "serif",
}
)


def main(image_file: str | Path):
img = cv.imread(str(Path(image_file).resolve()))
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
img = (img / img.max()).astype("float32")
fig = plt.figure(figsize=(7 * 2, 7))

ax = fig.add_subplot(221)
ax.imshow(img, "gray")
ax.set_title("image")
ax.axis("off")

ax = fig.add_subplot(222)
img_fft = fft.fft2(img)
power = np.log(fft.fftshift(abs(img_fft)))
ax.imshow(power, "gray")
ax.set_title("image FT")
ax.axis("off")

ax = fig.add_subplot(223)
mask = np.zeros_like(img, dtype="uint8")
mask[371:434, 1256:1326] = 1
mask[456:474, 1327:1385] = 1
mask[486:523, 1434:1491] = 1
mask[605:644, 1333:1400] = 1
ax.imshow(mask, "gray")
ax.set_title("mask")
ax.axis("off")

ax = fig.add_subplot(224)
mask_inverse = np.logical_not(mask).astype("uint8")
clean = fft.fftshift(img_fft) * mask_inverse
clean = fft.ifft2(clean)
clean = abs(clean)
clean = (clean / clean.max()).astype("float32")
ax.imshow(clean, "gray")
plt.tight_layout()
plt.show()


if __name__ == "__main__":
main(sys.argv[1])
Loading

0 comments on commit 5542b4b

Please sign in to comment.