From 33acea6e1977dcbb6fd6a892be5d0b789acb3116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rostislav=20L=C3=A1n?= Date: Fri, 24 Feb 2023 14:46:16 +0100 Subject: [PATCH] Added requirements for venv, removed some includes --- requirements.txt | 8 ++++++++ src/filters.py | 29 ++++++++++++++++++----------- src/main.py | 7 +++---- 3 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..643f072 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +matplotlib==3.5.3 +numpy==1.23.3 +numpy-stl==3.0.0 +opencv-python==4.7.0.72 +scikit-image==0.19.3 +scipy==1.9.3 +stl==0.0.3 + diff --git a/src/filters.py b/src/filters.py index e226822..e302af5 100644 --- a/src/filters.py +++ b/src/filters.py @@ -4,11 +4,10 @@ """ import numpy as np -#import matplotlib.pyplot as plt import cv2 as cv from skimage import filters as skiflt from skimage import restoration as skirest -from scipy import signal as sig +#from scipy import signal as sig # Parent class for all the filters @@ -142,22 +141,27 @@ class denoise_bilateral(filter): super().__init__(img) def apply(self, params): + + # Standard deviation for grayvalue/color distance. + # A larger value results in averaging of pixels with larger radiometric differences. sigmaColor = float(params["sigmaColor"] ) if params["sigmaColor"] else 0.1 + + # Standard deviation for range distance. + # A larger value results in averaging of pixels with larger spatial differences. + sigmaSpace = float(params["sigmaSpace"] ) if params["sigmaSpace"] else 15.0 - channelAxis = int(params["channelAxis"] - ) if params["channelAxis"] else None + # Repetition of filter application. iterations = int(params["iterations"]) if params["iterations"] else 1 #print("with params: sigma_color: " + str(sigmaColor) + - # " sigma_spatial: " + str(sigmaSpace) + " channel_axis: " + - # str(channelAxis) + " iterations: " + str(iterations)) + # " sigma_spatial: " + str(sigmaSpace) + " iterations: " + str(iterations)) for i in range(iterations): self.img = skirest.denoise_bilateral( self.img, sigma_color=sigmaColor, - sigma_spatial=sigmaSpace, channel_axis=channelAxis) + sigma_spatial=sigmaSpace, channel_axis=None) class denoise_tv_chambolle(filter): @@ -171,16 +175,18 @@ class denoise_tv_chambolle(filter): super().__init__(img) def apply(self, params): + + # Denoising weight. The greater weight, the more denoising. weight = float(params["weight"]) if params["weight"] else 0.1 - channelAxis = int(params["channelAxis"] - ) if params["channelAxis"] else None + + # Maximal number of iterations used for the optimization. iterations = int(params["iterations"]) if params["iterations"] else 1 #print("with params: weight: " + str(weight) + - # " channel_axis: " + str(channelAxis) + " iterations: " + str(iterations)) + # " iterations: " + str(iterations)) for i in range(iterations): self.img = skirest.denoise_tv_chambolle( - self.img, weight=weight, channel_axis=channelAxis) + self.img, weight=weight, channel_axis=None) class sharpen(filter): @@ -235,6 +241,7 @@ class unsharp_mask_scikit(filter): def apply(self, params): radius = int(params["radius"]) if params["radius"] else 3 amount = float(params["amount"]) if params["amount"] else 1 + # TODO: i have no idea what this is or how to use it channelAxis = int(params["channelAxis"] ) if params["channelAxis"] else None diff --git a/src/main.py b/src/main.py index 2dd9429..3b3797f 100644 --- a/src/main.py +++ b/src/main.py @@ -7,15 +7,14 @@ import argparse as ap import sys import json +import math from os.path import exists # Libraries for image processing import numpy as np import matplotlib.pyplot as plt -#from PIL import Image import cv2 as cv from stl import mesh -import math # Import custom image filter library import filters as flt @@ -158,7 +157,7 @@ class app: "ksize", "kernel", "sigmaX", "sigmaY", "sigmaColor", "sigmaSpace", "d", "anchor", "iterations", "op", "strength", "amount", "radius", "weight", "channelAxis", - "theta", "sigma", "lambda", "gamma", "psi"} + "theta", "sigma", "lambda", "gamma", "psi", "shape"} for key in possible_params: if params.get(key) is None: @@ -576,7 +575,7 @@ class app: def save_stl(self): '''Save final mesh to stl file. ''' - + # TODO: add a hash function to create filename specific to input image and preset if self.mode == "3d": self.mesh_finger.save(self.stl_file) else: