forked from SRA-VJTI/Pixels_Seminar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Port to C++] Morphological Operations (SRA-VJTI#76)
* added code for erosion and dilation * added code for opening, closing and gradient * added readme * removed template files * added assets folder * changed path for images * Change naming scheme * Rename main.cpp to relevenat 'algo'.cpp * Modify Makefile accordingly * Major changes 1] Generalised modules for any size kernel 2] Modified file structure 3] Added module for padding of images * Add new image to assets folder * Add dependencies to Makefiles * Take image path as commandline argument * Remove redundant files * - Add table of contents - Break long paragraphs in smaller sections. * - Remove redundant function from helper.hpp - Add comments * Rename Assets->assets Rename Readme.md -> README.md * Revert Makefile changes * Change format of helper.hpp - made separate src and include folder * Modify Makefile * Change path of include file * Rename files - helper.cpp -> morphology.cpp - helper.hpp -> morphology.hpp * Change image path * Change helper -> morphology --------- Co-authored-by: Smit1603 <[email protected]>
- Loading branch information
1 parent
9f929fe
commit c4b0211
Showing
26 changed files
with
563 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <iostream> | ||
#include <opencv2/core/core.hpp> | ||
|
||
#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
#include "../include/morphology.hpp" | ||
|
||
using namespace cv; | ||
using namespace std; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if ( argc != 2 ) | ||
{ | ||
std::cout <<"usage: ./output <Image_Path>\n"; | ||
return -1; | ||
} | ||
|
||
// Reading the Image | ||
Mat source_image = imread(argv[1], IMREAD_GRAYSCALE); | ||
|
||
// Check if the image is created successfully or not | ||
if (!source_image.data) | ||
{ | ||
cout << "Could not open or find the image\n"; | ||
return 0; | ||
} | ||
|
||
// creating container for output image according to size and type of source image | ||
Mat output_image{source_image.size(), source_image.type()}; | ||
|
||
// Applying erosion on source image | ||
int kernel_size = 3; | ||
output_image = erosion(source_image, output_image, kernel_size); | ||
|
||
// Displaying both source and output image | ||
namedWindow("source", WINDOW_NORMAL); | ||
imshow("source", source_image); | ||
|
||
namedWindow("output", WINDOW_NORMAL); | ||
imshow("output", output_image); | ||
|
||
waitKey(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
output: 1_erosion.cpp ../include/morphology.hpp ../src/morphology.cpp | ||
g++ 1_erosion.cpp ../src/morphology.cpp -o output `pkg-config --cflags --libs opencv4` | ||
|
||
clean: | ||
rm output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <iostream> | ||
#include <opencv2/core/core.hpp> | ||
|
||
#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
#include "../include/morphology.hpp" | ||
|
||
using namespace cv; | ||
using namespace std; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if ( argc != 2 ) | ||
{ | ||
std::cout <<"usage: ./output <Image_Path>\n"; | ||
return -1; | ||
} | ||
|
||
// Reading the Image | ||
Mat source_image = imread(argv[1], IMREAD_GRAYSCALE); | ||
|
||
// Check if the image is created successfully or not | ||
if (!source_image.data) | ||
{ | ||
std::cout << "Could not open or find the image\n"; | ||
return 0; | ||
} | ||
|
||
// creating container for output image according to size and type of source image | ||
Mat output_image{source_image.size(), source_image.type()}; | ||
|
||
// Applying dilation on source image | ||
int kernel_size = 3; | ||
output_image = dilation(source_image, output_image, kernel_size); | ||
|
||
// Displaying both source and output image | ||
namedWindow("source", WINDOW_NORMAL); | ||
imshow("source", source_image); | ||
|
||
namedWindow("output", WINDOW_NORMAL); | ||
imshow("output", output_image); | ||
|
||
waitKey(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
output: 2_dilation.cpp ../include/morphology.hpp ../src/morphology.cpp | ||
g++ 2_dilation.cpp ../src/morphology.cpp -o output `pkg-config --cflags --libs opencv4` | ||
|
||
clean: | ||
rm output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <iostream> | ||
#include <opencv2/core/core.hpp> | ||
|
||
#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
#include "../include/morphology.hpp" | ||
|
||
using namespace cv; | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if ( argc != 2 ) | ||
{ | ||
std::cout <<"usage: ./output <Image_Path>\n"; | ||
return -1; | ||
} | ||
|
||
// Reading the Image | ||
Mat source_image = imread(argv[1], IMREAD_GRAYSCALE); | ||
|
||
// Check if the image is created successfully or not | ||
if (!source_image.data) { | ||
std::cout << "Could not open or find the image\n"; | ||
return 0; | ||
} | ||
|
||
// creating container for output image according to size and type of source image | ||
Mat temp1{source_image.size(), source_image.type()}; | ||
Mat output_image{source_image.size(), source_image.type()}; | ||
|
||
//Applying erosion on source image | ||
int kernel_size_erosion = 3; | ||
temp1 = erosion(source_image, temp1,kernel_size_erosion); | ||
|
||
// Applying dilation on erroded image | ||
int kernel_size_dilation = 3; | ||
output_image = dilation(temp1, output_image,kernel_size_dilation); | ||
|
||
//Displaying both source and output image | ||
namedWindow("source", WINDOW_NORMAL); | ||
imshow("source", source_image); | ||
|
||
namedWindow("output", WINDOW_NORMAL); | ||
imshow("output", output_image); | ||
|
||
waitKey(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
output: 3_opening.cpp ../include/morphology.hpp ../src/morphology.cpp | ||
g++ 3_opening.cpp ../src/morphology.cpp -o output `pkg-config --cflags --libs opencv4` | ||
|
||
clean: | ||
rm output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <iostream> | ||
#include <opencv2/core/core.hpp> | ||
|
||
#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
#include "../include/morphology.hpp" | ||
|
||
using namespace cv; | ||
using namespace std; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if ( argc != 2 ) | ||
{ | ||
std::cout <<"usage: ./output <Image_Path>\n"; | ||
return -1; | ||
} | ||
|
||
// Reading the Image | ||
Mat source_image = imread(argv[1], IMREAD_GRAYSCALE); | ||
|
||
// Check if the image is created successfully or not | ||
if (!source_image.data) { | ||
std::cout << "Could not open or find the image\n"; | ||
return 0; | ||
} | ||
|
||
// creating container for output image according to size and type of source image | ||
Mat temp1{source_image.size(), source_image.type()}; | ||
Mat output_image{source_image.size(), source_image.type()}; | ||
|
||
//Applying dilation on source image | ||
int kernel_size_dilation = 3; | ||
temp1 = dilation(source_image, temp1,kernel_size_dilation); | ||
|
||
// Applying erosion on dilated image | ||
int kernel_size_erosion = 3; | ||
output_image = erosion(temp1, output_image,kernel_size_erosion); | ||
|
||
//Displaying both source and output image | ||
namedWindow("source", WINDOW_NORMAL); | ||
imshow("source", source_image); | ||
|
||
namedWindow("output", WINDOW_NORMAL); | ||
imshow("output", output_image); | ||
|
||
waitKey(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
output: 4_closing.cpp ../include/morphology.hpp ../src/morphology.cpp | ||
g++ 4_closing.cpp ../src/morphology.cpp -o output `pkg-config --cflags --libs opencv4` | ||
|
||
clean: | ||
rm output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <iostream> | ||
#include <opencv2/core/core.hpp> | ||
|
||
#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
#include "../include/morphology.hpp" | ||
|
||
using namespace cv; | ||
using namespace std; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if (argc != 2) | ||
{ | ||
std::cout << "usage: ./output <Image_Path>\n"; | ||
return -1; | ||
} | ||
|
||
// Reading the Image | ||
Mat source_image = imread(argv[1], IMREAD_GRAYSCALE); | ||
|
||
// Check if the image is created successfully or not | ||
if (!source_image.data) | ||
{ | ||
std::cout << "Could not open or find the image\n"; | ||
return 0; | ||
} | ||
|
||
// creating container for output image according to size and type of source image | ||
Mat erod{source_image.size(), source_image.type()}; | ||
Mat dill{source_image.size(), source_image.type()}; | ||
Mat gradient{source_image.size(), source_image.type()}; | ||
|
||
// Applying erosion on source image | ||
int kernel_size_erosion = 3; | ||
erod = erosion(source_image, erod, kernel_size_erosion); | ||
|
||
// Applying dilation on source image | ||
int kernel_size_dilation = 3; | ||
dill = dilation(source_image, dill, kernel_size_dilation); | ||
|
||
// Taking difference of erroded and dilated image to get gradient | ||
gradient = difference(dill, erod, gradient); | ||
|
||
//Displaying both source and output image | ||
namedWindow("source", WINDOW_NORMAL); | ||
imshow("source", source_image); | ||
|
||
namedWindow("gradient", WINDOW_NORMAL); | ||
imshow("gradient", gradient); | ||
|
||
waitKey(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
output: 5_gradient.cpp ../include/morphology.hpp ../src/morphology.cpp | ||
g++ 5_gradient.cpp ../src/morphology.cpp -o output `pkg-config --cflags --libs opencv4` | ||
|
||
clean: | ||
rm output |
Empty file.
Empty file.
Oops, something went wrong.