diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1807e69 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.8-slim + +RUN apt-get update && apt-get upgrade -y +RUN apt-get install -y \ + libgl1-mesa-dev \ + libglib2.0-0 \ + libsm6 \ + libxext6 \ + libxrender-dev \ + libx11-dev + +COPY ./requirements.txt ./ + +RUN pip3 install --upgrade pip setuptools +RUN pip3 install --upgrade wheel +RUN pip3 install -r requirements.txt + +ENV DISPLAY=host.docker.internal:0.0 + +WORKDIR /code +ADD . . + +CMD python3 main.py diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..dbac373 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +{ + "name": "sato_container", + // Dockerfileでイメージ・コンテナを作成 + "context": "..", + "dockerFile": "Dockerfile", + // リモート先のVS Codeにインストールする拡張機能 + "extensions": [ + "ms-python.python" + ], + "settings": { + // 構文チェックを行うようにする + "python.linting.enabled": true, + // 保存時に構文チェックを行う + "python.linting.lintOnSave": true, + // 構文チェックをpylintで行わないようにする (※規定値がtrueなため) + "python.linting.pylintEnabled": false, + // 構文チェックをflake8で行うようにする + "python.linting.flake8Enabled": true, + // flake8のパス (※pyproject-flake8を導入している場合はpflake8で上書きする必要がある) + "python.linting.flake8Path": "/usr/local/bin/pflake8", + // mypyを有効化する + "python.linting.mypyEnabled": true, + // フォーマットをblackで行うようにする + "python.formatting.provider": "black", + // pythonファイルの設定 + "[python]": { + // 保存時にimport文のソートなどを行う + "editor.codeActionsOnSave": { + "source.organizeImports": true + }, + // 保存時にフォーマットを行う + "editor.formatOnSave": true + } + }, +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f86a692 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +# 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/ +pip-wheel-metadata/ +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/ + +# 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 +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.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/ + + +.vscode/ +.mypy_cache/ diff --git a/README.md b/README.md index b566712..5645c5a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,16 @@ DenoiseEsoImg =============== -食道内視鏡映像にあるノイズをなんとか取り除こうと努力したアプリケーション \ No newline at end of file +食道内視鏡映像にあるノイズをなんとか取り除こうと努力したアプリケーション + +
+ +--- + +## 準備 +- 同ディレクトリ内にpng形式の内視鏡画像を入れておく +## 稼働方法 +1. イメージのビルド +docker build -f .devcontainer/Dockerfile -t denoise . +2. コンテナの稼働 +docker build run -it denoise \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..29ffe72 --- /dev/null +++ b/main.py @@ -0,0 +1,64 @@ +import os.path as osp +from glob import glob + +import cv2 +import numpy as np +from tqdm import tqdm + + +def make_dataset_list(): + imgs_path_list = glob("./*.png") + + dataset_list = [] + for path in imgs_path_list: + img_num = int(osp.basename(path)[:-4]) + target_path = osp.join(osp.dirname(path), "{:08}.png".format(img_num + 1)) + if osp.exists(target_path): + dataset_list.append({"seq_0": path, "seq_1": target_path}) + + return dataset_list + + +dataset_list = make_dataset_list() +print(f"samples: {len(dataset_list)}") + +mae_list = [] +for pair in tqdm(dataset_list): + seq_0 = cv2.imread(pair["seq_0"]) + seq_1 = cv2.imread(pair["seq_1"]) + + img_num = int(osp.basename(pair["seq_0"])[:-4]) + cv2.imwrite(f"./diff/diff_{img_num}_src.jpg", np.clip(np.abs(seq_0 - seq_1), 0, 255).astype(np.uint8)) + + cv2.imshow("diff1", np.clip(np.abs(seq_0 - seq_1), 0, 255).astype(np.uint8)) + + # medianフィルタ + # seq_0 = cv2.medianBlur(seq_0, 3) + # seq_1 = cv2.medianBlur(seq_1, 3) + + # Gaussianフィルタ + # seq_0 = cv2.GaussianBlur(seq_0, (3, 3), 0) + # seq_1 = cv2.GaussianBlur(seq_1, (3, 3), 0) + + # 移動平均フィルタ + # seq_0 = cv2.blur(seq_0, (3, 3)) + # seq_1 = cv2.blur(seq_1, (3, 3)) + + # バイラテラルフィルタ + # seq_0 = cv2.bilateralFilter(seq_0, 3, 20, 20) + # seq_1 = cv2.bilateralFilter(seq_1, 3, 20, 20) + + # ノンローカルミーンフィルタ + seq_0 = cv2.fastNlMeansDenoisingColored(seq_0, None, 10, 10, 7, 21) + seq_1 = cv2.fastNlMeansDenoisingColored(seq_1, None, 10, 10, 7, 21) + + cv2.imshow("seq_0", seq_0) + cv2.imshow("seq_1", seq_1) + + cv2.imwrite(f"./diff/diff_{img_num}_denoise.jpg", np.clip(np.abs(seq_0 - seq_1), 0, 255).astype(np.uint8)) + cv2.imshow("diff2", np.clip(np.abs(seq_0 - seq_1), 0, 255).astype(np.uint8)) + + mae_list.append(np.mean(np.abs(seq_0 - seq_1))) + cv2.waitKey(3000) + +print(f"ave_mae: {sum(mae_list) / len(mae_list)}") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9d84e25 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[tool.isort] +profile = "black" +line_length = 120 +skip_glob = "*/migrations/*.py" + +[tool.black] +line-length = 120 +include = '\.pyi?$' +extend-exclude = ''' +/( + | \.git + | templates + | migrations +)/ +''' + +[tool.flake8] +max-line-length = 120 +extend-ignore = "E203,W503" + + +[tool.mypy] +follow-imports = "normal" +ignore_missing_imports = true +show_column_numbers = true +pretty = false +disallow_untyped_calls = true +disallow_untyped_defs = true + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..30c434f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,18 @@ +black==22.1.0 +click==8.0.4 +flake8==4.0.1 +isort==5.10.1 +mccabe==0.6.1 +mypy==0.931 +mypy-extensions==0.4.3 +numpy==1.22.2 +opencv-python==4.5.5.62 +pathspec==0.9.0 +platformdirs==2.5.1 +pycodestyle==2.8.0 +pyflakes==2.4.0 +pyproject-flake8==0.0.1a2 +toml==0.10.2 +tomli==2.0.1 +tqdm==4.63.0 +typing_extensions==4.1.1 \ No newline at end of file