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

Port to C++: Morphological Operations #76

Merged
merged 22 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions 4_cv_basics/6_morphology/1_erosion/1_erosion.cpp
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;
}
5 changes: 5 additions & 0 deletions 4_cv_basics/6_morphology/1_erosion/Makefile
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
47 changes: 47 additions & 0 deletions 4_cv_basics/6_morphology/2_dilation/2_dilation.cpp
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;
}
5 changes: 5 additions & 0 deletions 4_cv_basics/6_morphology/2_dilation/Makefile
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
51 changes: 51 additions & 0 deletions 4_cv_basics/6_morphology/3_opening/3_opening.cpp
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;
}
5 changes: 5 additions & 0 deletions 4_cv_basics/6_morphology/3_opening/Makefile
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
51 changes: 51 additions & 0 deletions 4_cv_basics/6_morphology/4_closing/4_closing.cpp
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;
}
5 changes: 5 additions & 0 deletions 4_cv_basics/6_morphology/4_closing/Makefile
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
56 changes: 56 additions & 0 deletions 4_cv_basics/6_morphology/5_gradient/5_gradient.cpp
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;
}
5 changes: 5 additions & 0 deletions 4_cv_basics/6_morphology/5_gradient/Makefile
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.
Loading