Download the following images and write a C++ program with OpenCV to: (Chegg won
ID: 3679916 • Letter: D
Question
Download the following images and write a C++ program with OpenCV to:
(Chegg won't let me upload these so linking them)
https://u.teknik.io/X5X5s.tiff
https://u.teknik.io/nojS1.tiff
1. Remove the noise from the image (a) while keeping the object the same using morphological filtering.
2. Separate the two types of blobs image (b) (i.e, produce two output images: one with large blobs only and one with small blobs only).
3. write your own program for gray-scale dilation and erosion with 3x3 binary structuring element.
Note: For questions 1 and 2, you can use OpenCV’s morphological functions, but not question 3
Explanation / Answer
Here you go :
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("X5X5s.tiff", 0);
// Create a structuring element (SE)
int morph_size = 2;
Mat element = getStructuringElement( MORPH_RECT, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
cout<<element;
Mat dst; // result matrix
// Apply the specified morphology operation
for (int i=1;i<10;i++)
{
morphologyEx( src, dst, MORPH_TOPHAT, element, Point(-1,-1), i );
//morphologyEx( src, dst, MORPH_TOPHAT, element ); // here iteration=1
imshow("source", src);
imshow("result", dst);
waitKey(1000);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.