项目作者: Oxid15

项目描述 :
Implementation of an Image Smoothing Algorithm
高级语言: C++
项目地址: git://github.com/Oxid15/Image-Smoothing-Algorithm-Based-on-Gradient-Analysis.git


Image Smoothing Algorithm Based on Gradient Analysis

DOI

This repository contains C++ and Python 3 implementation of an image smoothing algorithm that was proposed in this publication.

example1

How to use code

Requirements for C++:

  • opencv 4.3.0 if you want Mat type support

Here is the simple example of filter usage with opencv Mat images:

  1. #include "FilterBasedOnGradientAnalysis.cpp"
  2. int main()
  3. {
  4. cv::Mat img = cv::imread("your_input_file_name", cv::IMREAD_COLOR); //read image using opencv from file into Mat type
  5. int kernelSize = 3; //set kernelSize = 3 for filtering with 3x3 kernel
  6. int runsNumber = 2; //set number of runs: parameter n is 1 by default
  7. Filter<float, uint8_t> filter; //create the instance of filter
  8. cv::Mat output = filter(img, kernelSize, runsNumber); //smooth image
  9. cv::imwrite("your_output_file_name", output); //write the result
  10. return 0;
  11. }

Python requirements are in file requirements.txt
use:
pip install --upgrade pip
pip install -r requirements.txt

Here is example with python:

  1. import filter_based_on_gradient_analysis as fga
  2. import cv2
  3. img = cv2.imread('your_input_file_name', cv2.IMREAD_COLOR) # read images using opencv from file
  4. kernel_size = 3 # set kernel_size = 3 for filtering with 3x3 kernel
  5. runs_number = 2 # set number of runs: parameter n is 1 by default
  6. output = fga.smooth(img, kernel_size, n=runs_number) # smooth image
  7. cv2.imwrite('your_output_file_name', output) # write the result

General idea

Our algorithm uses filtering and to achieve edge-preserving smoothing it uses two components of gradient vectors: their magnitudes (or lengths) and directions. Our method discriminates between two types of boundaries in given neighborhood: regular and irregular ones.
boundaries
Regular boundaries have small deviations of gradient angles and the opposite for irregular ones. To measure closeness of angles cosine of doubled difference is used. As additional measure that helps to discriminate the types of boundaries inverted gradient values were used.
gradients
When gradient magnitudes are inverted bigger values refer to textures (insignificant changes in gradient) and smaller refer to strong boundaries. So textures would have bigger weights and hence they would appear smoother. We also propose to smooth image of gradient magnitudes with median filter to enhance visual quality of results. The method proposed in this paper is easy to implement and compute and it gives good results in comparison with other techniques like bilateral filter.

Citation

If you used the code or want to reference this method in your work, please cite:

  1. @inproceedings{gudkov2020image,
  2. title={Image smoothing algorithm based on gradient analysis},
  3. author={Gudkov, Vladimir and Moiseev, Ilia},
  4. booktitle={2020 Ural Symposium on Biomedical Engineering, Radioelectronics and Information Technology (USBEREIT)},
  5. pages={403--406},
  6. year={2020},
  7. organization={IEEE}
  8. }