Mii Opencv
Mii Opencv
h>
using namespace std;
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
}
void Threshold(int pos, void* userdata) {
threshold(srcImage, binarizedImage, threshold_value, max_value, THRESH_BINARY);
imshow("Binarization", binarizedImage);
}
void ShowImage(Mat img, const char* name, int x, int y)
{
CreateWindow(name, x, y);
imshow(name, img);
}
void Brightness(Mat src, Mat dst, int B) {
for (int i = 0; i < src.rows; i++) {
for (int j = 0; j < src.cols; j++) {
Vec3b PixelColor = src.at<Vec3b>(i, j);
for (int k = 0; k < 3; k++) {
if (PixelColor[k] + B > 255) {
PixelColor[k] = 255;
}
else {
PixelColor[k] += B;
}
}
dst.at<Vec3b>(i, j) = PixelColor;
}
}
}
int main()
{
// reading source file srcImage
srcImage = imread("Samples/Fish.jpg");
if (!srcImage.data)
{
cout << "Error! Cannot read source file. Press ENTER.";
waitKey(); // wait for a key press
return(-1);
}
ShowImage(srcImage, "Aliaksandr Shydlouski", 0, 0);
Mat blurImage;
blur(srcImage, blurImage, Size(5, 5));
ShowImage(blurImage, "Blur Image", 900, 0);
Mat LaplacianImage;
Laplacian(srcImage, LaplacianImage, CV_16S, 3);
Mat scaledLaplacianImage;
convertScaleAbs(LaplacianImage, scaledLaplacianImage);
ShowImage(scaledLaplacianImage, "Laplacian Image", 0, 300);
// rest of the code
Mat dilatedImage;
int iterations = 2;
Mat element = getStructuringElement(MORPH_RECT, Size(iterations * 2 + 1,
iterations * 2 + 1), Point(iterations, iterations));
dilate(CannyImage, dilatedImage, element);
ShowImage(dilatedImage, "Dilated Image", 300, 300);
Mat erodedImage;
erode(dilatedImage, erodedImage, element);
ShowImage(erodedImage, "Eroded Image", 600, 300);
//SHOW SHOW SHOW
Mat brightImage;
srcImage.copyTo(brightImage);
Brightness(srcImage, brightImage, 100);
ShowImage(brightImage, "Bright Image", 900, 300);
CreateWindow("Binarization", 0, 600);
createTrackbar("Threshold", "Binarization", &threshold_value, max_value,
Threshold);
Threshold(threshold_value, 0);
*/
Mat histogram;
calcHist(&greyImage, 1, 0, Mat(), histogram, 1, &histSize, histRange);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
normalize(histogram, histogram, 0, histImage.rows, NORM_MINMAX, -1, Mat());
for (int i = 1; i < histSize; i++)
{
int value = cvRound(histogram.at<float>(i));
line(histImage, Point(i, hist_h), Point(i, hist_h - value), Scalar(255,
255, 255), 1);
}
ShowImage(histImage, "Gray image histogram", 300, 300);
Mat equalizedImage;
equalizeHist(greyImage, equalizedImage);
ShowImage(equalizedImage, "Equalized image histogram Image", 900, 300);
Mat equalizedHistogram;
calcHist(&equalizedImage, 1, 0, Mat(), equalizedHistogram, 1, &histSize,
histRange);
Mat equalizedHistImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
normalize(equalizedHistogram, equalizedHistogram, 0, equalizedHistImage.rows,
NORM_MINMAX, -1, Mat());
for (int i = 1; i < histSize; i++)
{
int value = cvRound(equalizedHistogram.at<float>(i));
line(equalizedHistImage, Point(i, hist_h), Point(i, hist_h - value),
Scalar(255, 255, 255), 1);
}
ShowImage(equalizedHistImage, "Histogram Equalized", 900, 300);
waitKey(0);
}