Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added all standard morphological transformations #541

Merged
merged 28 commits into from
Feb 13, 2021

Conversation

meshtag
Copy link
Member

@meshtag meshtag commented Jan 21, 2021

Description

This pull request adds all standard morphological transformations in Boost Gil library.

Summary of applied morphological concepts:

  1. Dilation: Gives the maximum overlapped value with respect to the structuring element to the pixel overlapping with the center element of structuring element.We can vary the number of times dilation happens by varying the
    argument 'iterations' in the dilate function.
  2. Erosion: Give the minimum overlapped value with respect to the structuring element to the pixel overlapping with the center element of structuring element.We can vary the number of times erosion happens by varying the
    argument 'iterations' in the erode function.
  3. Opening: Opening is just another name of erosion followed by dilation.
    It is useful in removing noise.
  4. Closing: Closing is reverse of Opening, Dilation followed by Erosion.
    It is useful in closing small holes inside the foreground objects, or small black points on the object.
  5. Morphological Gradient: It is the difference between dilation and erosion of an image.
    The result will look like the outline of the object.
  6. Top Hat: It is the difference between input image and Opening of the image.
  7. Black Hat: It is the difference between the closing of the input image and input image.
    Functions have been made for applying above morphological transformations.

References

https://homepages.inf.ed.ac.uk/rbf/HIPR2/dilate.htm
https://homepages.inf.ed.ac.uk/rbf/HIPR2/erode.htm
https://docs.opencv.org/master/d9/d61/tutorial_py_morphological_ops.html

Tasklist

  • Add test case(s)
  • Ensure all CI builds pass - RIP Travis CI, ignored and replaced with GitHub Actions
  • Review and approve

include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
example/morphology.cpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
example/morphology.cpp Outdated Show resolved Hide resolved
example/morphology.cpp Outdated Show resolved Hide resolved
@simmplecoder
Copy link
Contributor

simmplecoder commented Jan 24, 2021

Please format your files with clang-format, link to the most conforming config. Please do the reformat in its own commit, separate from other changes.

example/morphology.cpp Outdated Show resolved Hide resolved
@mloskot
Copy link
Member

mloskot commented Jan 25, 2021

Nitpick: If the example/original.png corresponds to example/morphology.hpp, could you rename it to example/morphology_original.png please?

@mloskot
Copy link
Member

mloskot commented Jan 25, 2021

@meshtag I looked into comparing initial work on the morphological operations by @ayushbansal07 in PR #430 and your work, and I don't see a copying one to the other, but if you have used @ayushbansal07 's work in any way, then please credit him adding relevant copyright notice. I leave it to your judgement.

One thing that Ayush does nicely is the Doxygen comments, so I'd suggest to look at those.


It would be good if you could update your PR based on the latest changes in the develop branch.
Then, let us know when it is ready to continue with another review iteration(s).


You seem to be saving on whitespaces e.g. //This in code vs // This and 1.Dilation:Gives vs 1. Dilation: Gives in this PR description, which I have taken the liberty to edit and fix.
You may want to check the spacebar key of your keyboard, it may need fixing ;-)
Seriously, if you could give a bit love to readable formatting of your commends and writing, it would save us on review iterations.

@mloskot mloskot added the cat/feature New feature or functionality label Jan 25, 2021
@mloskot
Copy link
Member

mloskot commented Jan 26, 2021

@meshtag If you update your PR from the latest develop you should get reliable CI builds as we've just replaced Travis CI with GitHub Actions

Copy link
Member

@mloskot mloskot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a another round of my review which is mostly nitpicks about missing whitespaces.

example/morphology.cpp Outdated Show resolved Hide resolved
example/morphology.cpp Outdated Show resolved Hide resolved
example/morphology.cpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
test/core/image_processing/morphology.cpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
include/boost/gil/image_processing/morphology.hpp Outdated Show resolved Hide resolved
@meshtag
Copy link
Member Author

meshtag commented Jan 29, 2021

@mloskot ,apologies for making so many whitespace errors and thanks a lot for your patience and effort pointing them out.

@mloskot
Copy link
Member

mloskot commented Jan 29, 2021

@mloskot ,apologies for making so many whitespace errors and thanks a lot for your patience and effort pointing them out.

There is no need to apologies, we're all learning. Please, consider @simmplecoder advice in #541 (comment)


I noticed morphology.cpp is missing from example/Jamfile, so it does not build together with all other examples, e.g.

cd libs/gil
b2 cxxstd=11 variant=release example

or

b2 cxxstd=11 variant=release example//morphology

@simmplecoder
Copy link
Contributor

Alright, this is probably last round of reviews. Please consider changes I suggested. To reformat files using my .clang-format you can either download new version (mine is >=10 I believe) or build it from source or I will just send you a patch tomorrow if changes will be ready. Also please address conflicts with recent develop changes. If I forget to send you patches, please ping me, I do not want to stall you any longer.

@simmplecoder
Copy link
Contributor

Formatting still is not correct @meshtag . I do not think it is worth dealing with it on your own. I can just send you a patch. The easy way to understand that the formatter is not getting it right is by looking at space count per indent. It is 2 at the moment, should be 4.

@mloskot
Copy link
Member

mloskot commented Feb 9, 2021

Yes, @meshtag, although this may seem like an trivial annoyance, we want to fix any formatting issues before merge - the legacy code of GIL is already messy and we are slowly cleaning it up, so must keep new code as consistent as possible.

@meshtag
Copy link
Member Author

meshtag commented Feb 9, 2021

No problem @mloskot , I am having trouble figuring out why appveyor build is failing . Do I need to change/correct something?

@mloskot
Copy link
Member

mloskot commented Feb 9, 2021

@meshtag I think the key message of the log is Failed a day ago in 1 hr 10 min what suggests that we are hitting the AppVeyor limits:

Are there any build time restrictions?
All plans have maximum build job execution time of 60 minutes.

So, you don't need to do anything.

Rather, I will have to think which AppVeyor job to kick out :)

UPDATE: Done in 2676d31

Copy link
Member

@mloskot mloskot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meshtag Could you hit the "Resolve conversation" button for each of the thread that you have addressed its comments? This way we will have a clearer picture of what has been done and what not. Thanks.

Second, if you update this PR with the latest develop branch it will receive the AppVeyor fix.

@mloskot mloskot added this to the Boost 1.76+ milestone Feb 13, 2021
@mloskot mloskot added the core boost/gil label Feb 13, 2021
@simmplecoder simmplecoder merged commit 1e85267 into boostorg:develop Feb 13, 2021
@simmplecoder
Copy link
Contributor

compare-results.zip
python-morphops.zip
meshtag-morphops.zip
Here are comparison results with OpenCV

@mloskot
Copy link
Member

mloskot commented Feb 16, 2021

Thanks for the comparison. The results are looking good, I think.
Can you tell how did you generate the files in the compare-results.zip ?

@simmplecoder
Copy link
Contributor

The code I used to get the results from opencv is

import cv2
import numpy as np
import sys


def morphops(input_file: str, output_name: str):
    input_img = cv2.imread(input_file, cv2.IMREAD_GRAYSCALE)
    kernel = np.full((3, 3), 1, np.uint8)
    dilated = cv2.dilate(input_img, kernel, iterations=3)
    eroded = cv2.erode(input_img, kernel, iterations=3)
    cv2.imwrite(output_name + '_dilation.png', dilated)
    cv2.imwrite(output_name + '_erosion.png', eroded)


if __name__ == '__main__':
    morphops(sys.argv[1], sys.argv[2])

meshtag added a commit to meshtag/gil that referenced this pull request Mar 17, 2021
* Added all standard morphological transformations

* Improved comments and some other things

* Applied adviced changes

* Applied adviced changes

* Should handle grayscale dilation/erosion

* Checking

* Added test cases and improved code structure

* Added command line control

* Added command line control

* Rectified some things

* Rectified some more things

* Improved comments

* Improved comments

* Improved doxygen comments and added more test cases

* Improved compatibility for builds and rectifying whitespace use

* Minor improvement in comments

* Did clang formatting

* pushed enum class inside namespace 'detail' and some other things

* Should handle multichannel images

* Clang formatting attempt

* got rid of if/else comparators for target_element

* Adds morphology.hpp declaration in boost/gil.hpp

* Fix newline

* (std::max)(a, b) instead of std::max(a, b)

* Improved Formatting
meshtag added a commit to meshtag/gil that referenced this pull request Apr 21, 2021
* Added all standard morphological transformations

* Improved comments and some other things

* Applied adviced changes

* Applied adviced changes

* Should handle grayscale dilation/erosion

* Checking

* Added test cases and improved code structure

* Added command line control

* Added command line control

* Rectified some things

* Rectified some more things

* Improved comments

* Improved comments

* Improved doxygen comments and added more test cases

* Improved compatibility for builds and rectifying whitespace use

* Minor improvement in comments

* Did clang formatting

* pushed enum class inside namespace 'detail' and some other things

* Should handle multichannel images

* Clang formatting attempt

* got rid of if/else comparators for target_element

* Adds morphology.hpp declaration in boost/gil.hpp

* Fix newline

* (std::max)(a, b) instead of std::max(a, b)

* Improved Formatting
meshtag added a commit to meshtag/gil that referenced this pull request Apr 22, 2021
* Added all standard morphological transformations

* Improved comments and some other things

* Applied adviced changes

* Applied adviced changes

* Should handle grayscale dilation/erosion

* Checking

* Added test cases and improved code structure

* Added command line control

* Added command line control

* Rectified some things

* Rectified some more things

* Improved comments

* Improved comments

* Improved doxygen comments and added more test cases

* Improved compatibility for builds and rectifying whitespace use

* Minor improvement in comments

* Did clang formatting

* pushed enum class inside namespace 'detail' and some other things

* Should handle multichannel images

* Clang formatting attempt

* got rid of if/else comparators for target_element

* Adds morphology.hpp declaration in boost/gil.hpp

* Fix newline

* (std::max)(a, b) instead of std::max(a, b)

* Improved Formatting
@meshtag meshtag deleted the morphology branch August 21, 2021 18:50
@mloskot mloskot mentioned this pull request May 12, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat/feature New feature or functionality core boost/gil
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants