ora6
2
ora6/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
BIN
ora6/American_Eskimo_Dog.jpg
Normal file
|
After Width: | Height: | Size: 646 KiB |
BIN
ora6/Képek (morfológia)-20251030.zip
Normal file
BIN
ora6/Képek (élkeresés)-20251030.zip
Normal file
18
ora6/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4`
|
||||
LIBS = `pkg-config --libs opencv4`
|
||||
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
TARGET = main
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(OBJ) -o $@ $(LIBS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
BIN
ora6/annotalt_sejt.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
ora6/edges_noise.png
Normal file
|
After Width: | Height: | Size: 259 KiB |
BIN
ora6/galaxy.jpg
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
ora6/go2.png
Normal file
|
After Width: | Height: | Size: 997 KiB |
BIN
ora6/graycat.jpg
Normal file
|
After Width: | Height: | Size: 5.1 KiB |
BIN
ora6/hela.zip
Normal file
BIN
ora6/hela/0.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
ora6/hela/1.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/2.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
ora6/hela/3.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/4.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/5.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/6.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/7.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/8.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/9.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
126
ora6/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "histo.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) {
|
||||
assert(img.type() == CV_8UC1);
|
||||
|
||||
// CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz.
|
||||
histo = Mat::zeros(256, 1, CV_32S);
|
||||
for (int i = 0; i < img.rows; i++)
|
||||
for (int j = 0; j < img.cols; j++)
|
||||
histo.at<int>(img.at<uchar>(i, j))++;
|
||||
}
|
||||
|
||||
|
||||
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||
assert(img.type() == CV_8UC3);
|
||||
|
||||
vector<Mat> chs;
|
||||
split(img.clone(), chs);
|
||||
|
||||
Mat h0, h1, h2;
|
||||
Histo::calcHistoC1(chs[0], h0);
|
||||
Histo::calcHistoC1(chs[1], h1);
|
||||
Histo::calcHistoC1(chs[2], h2);
|
||||
|
||||
histo_vect.clear();
|
||||
histo_vect.push_back(h0);
|
||||
histo_vect.push_back(h1);
|
||||
histo_vect.push_back(h2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) {
|
||||
assert(histo.type() == CV_32S);
|
||||
|
||||
int pad = 10;
|
||||
canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3);
|
||||
|
||||
// a hisztogram alatti szurke sav rajzolasa
|
||||
for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
if (0 <= channel && channel <= 2) {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||
}
|
||||
else {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vec3b color(255, 255, 255);
|
||||
if (0 <= channel && channel <= 2) {
|
||||
color = Vec3b(0, 0, 0);
|
||||
color[channel] = 255;
|
||||
}
|
||||
|
||||
|
||||
double minv, maxv;
|
||||
minMaxLoc(histo, &minv, &maxv);
|
||||
|
||||
double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat
|
||||
|
||||
// a hisztogram rajzolasa
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
// egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1)
|
||||
int v = int(histo.at<int>(i) * scale) - 1;
|
||||
// canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast
|
||||
if (v >= 0)
|
||||
line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases) {
|
||||
assert(histos.size() == 3 &&
|
||||
histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S);
|
||||
|
||||
canvases.clear();
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histos[i], canvas, i);
|
||||
canvases.push_back(canvas.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::showHisto(Mat img, string title, int wait) {
|
||||
assert(img.type() == CV_8UC1 || img.type() == CV_8UC3);
|
||||
|
||||
if (img.type() == CV_8UC1) {
|
||||
Mat histo;
|
||||
Histo::calcHistoC1(img, histo);
|
||||
|
||||
// az ertekek konzolra iratasa
|
||||
//cout << histo << endl;
|
||||
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histo, canvas);
|
||||
imshow(title, canvas);
|
||||
}
|
||||
else if (img.type() == CV_8UC3) {
|
||||
vector<Mat> histos;
|
||||
Histo::calcHistoC3(img, histos);
|
||||
|
||||
vector<Mat> canvases;
|
||||
Histo::drawHistoC3(histos, canvases);
|
||||
|
||||
string str = "BGR";
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
imshow(title + "-" + str[i], canvases[i]);
|
||||
}
|
||||
}
|
||||
waitKey(wait);
|
||||
}
|
||||
32
ora6/histo.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
1 es 3 csatornas, csatornankent 8 bites kepekre:
|
||||
Histo::showHisto(img);
|
||||
*/
|
||||
#ifndef HISTO_H_
|
||||
#define HISTO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace Histo {
|
||||
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||
|
||||
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||
|
||||
/// <summary>
|
||||
/// Egy kep hisztogramjanak megjelenitese.
|
||||
/// </summary>
|
||||
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||
/// <param name="title">ablaknev</param>
|
||||
/// <param name="wait">varakoztatas</param>
|
||||
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif HISTO_H_
|
||||
BIN
ora6/labirintus.png
Normal file
|
After Width: | Height: | Size: 762 KiB |
26
ora6/main.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "histo.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(){
|
||||
Mat img = imread("dark_img.jpg", IMREAD_GRAYSCALE);
|
||||
imshow("img", img);
|
||||
Histo::showHisto(img);
|
||||
|
||||
double ah, fh;
|
||||
minMaxLoc(img, &ah, &fh);
|
||||
|
||||
fh = 30;
|
||||
|
||||
Mat dest = (ah == fh) ? img.clone() : (img-ah) * 255 / (fh-ah);
|
||||
|
||||
imshow("dest", dest);
|
||||
Histo::showHisto(dest, "eredmeny");
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
2
ora6/proj/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora6/proj/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4`
|
||||
LIBS = `pkg-config --libs opencv4`
|
||||
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
TARGET = main
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(OBJ) -o $@ $(LIBS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
126
ora6/proj/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "histo.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) {
|
||||
assert(img.type() == CV_8UC1);
|
||||
|
||||
// CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz.
|
||||
histo = Mat::zeros(256, 1, CV_32S);
|
||||
for (int i = 0; i < img.rows; i++)
|
||||
for (int j = 0; j < img.cols; j++)
|
||||
histo.at<int>(img.at<uchar>(i, j))++;
|
||||
}
|
||||
|
||||
|
||||
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||
assert(img.type() == CV_8UC3);
|
||||
|
||||
vector<Mat> chs;
|
||||
split(img.clone(), chs);
|
||||
|
||||
Mat h0, h1, h2;
|
||||
Histo::calcHistoC1(chs[0], h0);
|
||||
Histo::calcHistoC1(chs[1], h1);
|
||||
Histo::calcHistoC1(chs[2], h2);
|
||||
|
||||
histo_vect.clear();
|
||||
histo_vect.push_back(h0);
|
||||
histo_vect.push_back(h1);
|
||||
histo_vect.push_back(h2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) {
|
||||
assert(histo.type() == CV_32S);
|
||||
|
||||
int pad = 10;
|
||||
canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3);
|
||||
|
||||
// a hisztogram alatti szurke sav rajzolasa
|
||||
for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
if (0 <= channel && channel <= 2) {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||
}
|
||||
else {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vec3b color(255, 255, 255);
|
||||
if (0 <= channel && channel <= 2) {
|
||||
color = Vec3b(0, 0, 0);
|
||||
color[channel] = 255;
|
||||
}
|
||||
|
||||
|
||||
double minv, maxv;
|
||||
minMaxLoc(histo, &minv, &maxv);
|
||||
|
||||
double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat
|
||||
|
||||
// a hisztogram rajzolasa
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
// egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1)
|
||||
int v = int(histo.at<int>(i) * scale) - 1;
|
||||
// canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast
|
||||
if (v >= 0)
|
||||
line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases) {
|
||||
assert(histos.size() == 3 &&
|
||||
histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S);
|
||||
|
||||
canvases.clear();
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histos[i], canvas, i);
|
||||
canvases.push_back(canvas.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::showHisto(Mat img, string title, int wait) {
|
||||
assert(img.type() == CV_8UC1 || img.type() == CV_8UC3);
|
||||
|
||||
if (img.type() == CV_8UC1) {
|
||||
Mat histo;
|
||||
Histo::calcHistoC1(img, histo);
|
||||
|
||||
// az ertekek konzolra iratasa
|
||||
//cout << histo << endl;
|
||||
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histo, canvas);
|
||||
imshow(title, canvas);
|
||||
}
|
||||
else if (img.type() == CV_8UC3) {
|
||||
vector<Mat> histos;
|
||||
Histo::calcHistoC3(img, histos);
|
||||
|
||||
vector<Mat> canvases;
|
||||
Histo::drawHistoC3(histos, canvases);
|
||||
|
||||
string str = "BGR";
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
imshow(title + "-" + str[i], canvases[i]);
|
||||
}
|
||||
}
|
||||
waitKey(wait);
|
||||
}
|
||||
32
ora6/proj/histo.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
1 es 3 csatornas, csatornankent 8 bites kepekre:
|
||||
Histo::showHisto(img);
|
||||
*/
|
||||
#ifndef HISTO_H_
|
||||
#define HISTO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace Histo {
|
||||
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||
|
||||
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||
|
||||
/// <summary>
|
||||
/// Egy kep hisztogramjanak megjelenitese.
|
||||
/// </summary>
|
||||
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||
/// <param name="title">ablaknev</param>
|
||||
/// <param name="wait">varakoztatas</param>
|
||||
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif HISTO_H_
|
||||
BIN
ora6/proj/histo.o
Normal file
BIN
ora6/proj/main
Executable file
46
ora6/proj/main.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "histo.h"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
void thinning(const Mat img, Mat& skel){
|
||||
Mat mask, se, eroded, tmp;
|
||||
mask = img.clone();
|
||||
|
||||
se = Mat::zeros(img.size(), CV_8UC1);
|
||||
se = getStructuringElement(MORPH_CROSS, Size(3,3));
|
||||
|
||||
while(true){
|
||||
erode(mask, eroded, se);
|
||||
dilate(eroded, tmp, se);
|
||||
tmp = mask - tmp;
|
||||
skel = skel | tmp;
|
||||
eroded.copyTo(mask); //shallow copy miatt kulonben csak a fejlecet masolja
|
||||
|
||||
if(countNonZero(mask) == 0){
|
||||
break;
|
||||
}
|
||||
imshow("mask", mask);
|
||||
imshow("skel", skel);
|
||||
waitKey(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
Mat img = imread("../wrench.jpg", IMREAD_GRAYSCALE);
|
||||
Mat mask, skel;
|
||||
|
||||
threshold(img, mask, 80, 255, THRESH_BINARY_INV);
|
||||
//medianBlur(mask, mask, 7);
|
||||
thinning(mask, skel);
|
||||
|
||||
imshow("mask", mask);
|
||||
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
BIN
ora6/proj/main.o
Normal file
2
ora6/proj1/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora6/proj1/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4`
|
||||
LIBS = `pkg-config --libs opencv4`
|
||||
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
TARGET = main
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(OBJ) -o $@ $(LIBS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
126
ora6/proj1/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "histo.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) {
|
||||
assert(img.type() == CV_8UC1);
|
||||
|
||||
// CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz.
|
||||
histo = Mat::zeros(256, 1, CV_32S);
|
||||
for (int i = 0; i < img.rows; i++)
|
||||
for (int j = 0; j < img.cols; j++)
|
||||
histo.at<int>(img.at<uchar>(i, j))++;
|
||||
}
|
||||
|
||||
|
||||
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||
assert(img.type() == CV_8UC3);
|
||||
|
||||
vector<Mat> chs;
|
||||
split(img.clone(), chs);
|
||||
|
||||
Mat h0, h1, h2;
|
||||
Histo::calcHistoC1(chs[0], h0);
|
||||
Histo::calcHistoC1(chs[1], h1);
|
||||
Histo::calcHistoC1(chs[2], h2);
|
||||
|
||||
histo_vect.clear();
|
||||
histo_vect.push_back(h0);
|
||||
histo_vect.push_back(h1);
|
||||
histo_vect.push_back(h2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) {
|
||||
assert(histo.type() == CV_32S);
|
||||
|
||||
int pad = 10;
|
||||
canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3);
|
||||
|
||||
// a hisztogram alatti szurke sav rajzolasa
|
||||
for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
if (0 <= channel && channel <= 2) {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||
}
|
||||
else {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vec3b color(255, 255, 255);
|
||||
if (0 <= channel && channel <= 2) {
|
||||
color = Vec3b(0, 0, 0);
|
||||
color[channel] = 255;
|
||||
}
|
||||
|
||||
|
||||
double minv, maxv;
|
||||
minMaxLoc(histo, &minv, &maxv);
|
||||
|
||||
double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat
|
||||
|
||||
// a hisztogram rajzolasa
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
// egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1)
|
||||
int v = int(histo.at<int>(i) * scale) - 1;
|
||||
// canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast
|
||||
if (v >= 0)
|
||||
line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases) {
|
||||
assert(histos.size() == 3 &&
|
||||
histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S);
|
||||
|
||||
canvases.clear();
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histos[i], canvas, i);
|
||||
canvases.push_back(canvas.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::showHisto(Mat img, string title, int wait) {
|
||||
assert(img.type() == CV_8UC1 || img.type() == CV_8UC3);
|
||||
|
||||
if (img.type() == CV_8UC1) {
|
||||
Mat histo;
|
||||
Histo::calcHistoC1(img, histo);
|
||||
|
||||
// az ertekek konzolra iratasa
|
||||
//cout << histo << endl;
|
||||
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histo, canvas);
|
||||
imshow(title, canvas);
|
||||
}
|
||||
else if (img.type() == CV_8UC3) {
|
||||
vector<Mat> histos;
|
||||
Histo::calcHistoC3(img, histos);
|
||||
|
||||
vector<Mat> canvases;
|
||||
Histo::drawHistoC3(histos, canvases);
|
||||
|
||||
string str = "BGR";
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
imshow(title + "-" + str[i], canvases[i]);
|
||||
}
|
||||
}
|
||||
waitKey(wait);
|
||||
}
|
||||
32
ora6/proj1/histo.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
1 es 3 csatornas, csatornankent 8 bites kepekre:
|
||||
Histo::showHisto(img);
|
||||
*/
|
||||
#ifndef HISTO_H_
|
||||
#define HISTO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace Histo {
|
||||
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||
|
||||
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||
|
||||
/// <summary>
|
||||
/// Egy kep hisztogramjanak megjelenitese.
|
||||
/// </summary>
|
||||
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||
/// <param name="title">ablaknev</param>
|
||||
/// <param name="wait">varakoztatas</param>
|
||||
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif HISTO_H_
|
||||
BIN
ora6/proj1/histo.o
Normal file
67
ora6/proj1/main.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "histo.h"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
void Roberts(const Mat& img){
|
||||
Mat g, gx, gy, g2, edge, edge2;
|
||||
gx = Mat::zeros(img.size(), CV_16S);
|
||||
gy = Mat::zeros(img.size(), CV_16S);
|
||||
|
||||
for (int i = 0; i < img.rows -1; i++) {
|
||||
for (int j = 0; j < img.cols -1; j++) {
|
||||
gx.at<short>(i,j) = img.at<uchar>(i,j) - img.at<uchar>(i+1, j+1);
|
||||
gy.at<short>(i,j) = img.at<uchar>(i,j+1) - img.at<uchar>(i+1, j);
|
||||
}
|
||||
}
|
||||
|
||||
g = cv::abs(gx) + cv::abs(gy);
|
||||
|
||||
convertScaleAbs(g, g2);
|
||||
|
||||
threshold(g2, edge, 0, 255, THRESH_OTSU);
|
||||
threshold(g2, edge2, 0, 255, THRESH_TRIANGLE);
|
||||
|
||||
imshow("edge", edge);
|
||||
imshow("edg2", edge2);
|
||||
|
||||
//imshow("g", g * 255);
|
||||
//imshow("gx", gx * 255);
|
||||
//imshow("gy", gy * 255);
|
||||
}
|
||||
|
||||
void sobel(const Mat img){
|
||||
Mat g, g2, gx, gy;
|
||||
|
||||
Sobel(img, gx, CV_32F, 1,0);
|
||||
Sobel(img, gy, CV_32F, 0,1);
|
||||
|
||||
|
||||
//g = cv::abs(gx) + cv::abs(gy);
|
||||
//cv::sqrt(gx.mul(gx) + gy.mul(gy));
|
||||
convertScaleAbs(g, g2);
|
||||
//imshow("gx", gx / 255);
|
||||
//imshow("gx", gy / 255);
|
||||
//imshow("g2", g2);
|
||||
|
||||
Mat dest;
|
||||
Laplacian(img, dest, CV_16S, 3);
|
||||
convertScaleAbs(dest, dest);
|
||||
imshow("dest", dest);
|
||||
|
||||
waitKey(0);
|
||||
}
|
||||
|
||||
int main(){
|
||||
Mat img = imread("../go2.png", IMREAD_GRAYSCALE);
|
||||
imshow("ered", img);
|
||||
//Roberts(img);
|
||||
sobel(img);
|
||||
|
||||
while(waitKey(3) != 'q');
|
||||
return 0;
|
||||
}
|
||||
2
ora6/proj2/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora6/proj2/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4`
|
||||
LIBS = `pkg-config --libs opencv4`
|
||||
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
TARGET = main
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(OBJ) -o $@ $(LIBS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
126
ora6/proj2/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "histo.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) {
|
||||
assert(img.type() == CV_8UC1);
|
||||
|
||||
// CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz.
|
||||
histo = Mat::zeros(256, 1, CV_32S);
|
||||
for (int i = 0; i < img.rows; i++)
|
||||
for (int j = 0; j < img.cols; j++)
|
||||
histo.at<int>(img.at<uchar>(i, j))++;
|
||||
}
|
||||
|
||||
|
||||
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||
assert(img.type() == CV_8UC3);
|
||||
|
||||
vector<Mat> chs;
|
||||
split(img.clone(), chs);
|
||||
|
||||
Mat h0, h1, h2;
|
||||
Histo::calcHistoC1(chs[0], h0);
|
||||
Histo::calcHistoC1(chs[1], h1);
|
||||
Histo::calcHistoC1(chs[2], h2);
|
||||
|
||||
histo_vect.clear();
|
||||
histo_vect.push_back(h0);
|
||||
histo_vect.push_back(h1);
|
||||
histo_vect.push_back(h2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) {
|
||||
assert(histo.type() == CV_32S);
|
||||
|
||||
int pad = 10;
|
||||
canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3);
|
||||
|
||||
// a hisztogram alatti szurke sav rajzolasa
|
||||
for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
if (0 <= channel && channel <= 2) {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||
}
|
||||
else {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vec3b color(255, 255, 255);
|
||||
if (0 <= channel && channel <= 2) {
|
||||
color = Vec3b(0, 0, 0);
|
||||
color[channel] = 255;
|
||||
}
|
||||
|
||||
|
||||
double minv, maxv;
|
||||
minMaxLoc(histo, &minv, &maxv);
|
||||
|
||||
double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat
|
||||
|
||||
// a hisztogram rajzolasa
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
// egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1)
|
||||
int v = int(histo.at<int>(i) * scale) - 1;
|
||||
// canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast
|
||||
if (v >= 0)
|
||||
line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases) {
|
||||
assert(histos.size() == 3 &&
|
||||
histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S);
|
||||
|
||||
canvases.clear();
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histos[i], canvas, i);
|
||||
canvases.push_back(canvas.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::showHisto(Mat img, string title, int wait) {
|
||||
assert(img.type() == CV_8UC1 || img.type() == CV_8UC3);
|
||||
|
||||
if (img.type() == CV_8UC1) {
|
||||
Mat histo;
|
||||
Histo::calcHistoC1(img, histo);
|
||||
|
||||
// az ertekek konzolra iratasa
|
||||
//cout << histo << endl;
|
||||
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histo, canvas);
|
||||
imshow(title, canvas);
|
||||
}
|
||||
else if (img.type() == CV_8UC3) {
|
||||
vector<Mat> histos;
|
||||
Histo::calcHistoC3(img, histos);
|
||||
|
||||
vector<Mat> canvases;
|
||||
Histo::drawHistoC3(histos, canvases);
|
||||
|
||||
string str = "BGR";
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
imshow(title + "-" + str[i], canvases[i]);
|
||||
}
|
||||
}
|
||||
waitKey(wait);
|
||||
}
|
||||
32
ora6/proj2/histo.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
1 es 3 csatornas, csatornankent 8 bites kepekre:
|
||||
Histo::showHisto(img);
|
||||
*/
|
||||
#ifndef HISTO_H_
|
||||
#define HISTO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace Histo {
|
||||
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||
|
||||
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||
|
||||
/// <summary>
|
||||
/// Egy kep hisztogramjanak megjelenitese.
|
||||
/// </summary>
|
||||
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||
/// <param name="title">ablaknev</param>
|
||||
/// <param name="wait">varakoztatas</param>
|
||||
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif HISTO_H_
|
||||
14
ora6/proj2/main.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "histo.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
2
ora6/proj3/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora6/proj3/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4`
|
||||
LIBS = `pkg-config --libs opencv4`
|
||||
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
TARGET = main
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(OBJ) -o $@ $(LIBS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
126
ora6/proj3/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "histo.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) {
|
||||
assert(img.type() == CV_8UC1);
|
||||
|
||||
// CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz.
|
||||
histo = Mat::zeros(256, 1, CV_32S);
|
||||
for (int i = 0; i < img.rows; i++)
|
||||
for (int j = 0; j < img.cols; j++)
|
||||
histo.at<int>(img.at<uchar>(i, j))++;
|
||||
}
|
||||
|
||||
|
||||
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||
assert(img.type() == CV_8UC3);
|
||||
|
||||
vector<Mat> chs;
|
||||
split(img.clone(), chs);
|
||||
|
||||
Mat h0, h1, h2;
|
||||
Histo::calcHistoC1(chs[0], h0);
|
||||
Histo::calcHistoC1(chs[1], h1);
|
||||
Histo::calcHistoC1(chs[2], h2);
|
||||
|
||||
histo_vect.clear();
|
||||
histo_vect.push_back(h0);
|
||||
histo_vect.push_back(h1);
|
||||
histo_vect.push_back(h2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) {
|
||||
assert(histo.type() == CV_32S);
|
||||
|
||||
int pad = 10;
|
||||
canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3);
|
||||
|
||||
// a hisztogram alatti szurke sav rajzolasa
|
||||
for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
if (0 <= channel && channel <= 2) {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||
}
|
||||
else {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vec3b color(255, 255, 255);
|
||||
if (0 <= channel && channel <= 2) {
|
||||
color = Vec3b(0, 0, 0);
|
||||
color[channel] = 255;
|
||||
}
|
||||
|
||||
|
||||
double minv, maxv;
|
||||
minMaxLoc(histo, &minv, &maxv);
|
||||
|
||||
double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat
|
||||
|
||||
// a hisztogram rajzolasa
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
// egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1)
|
||||
int v = int(histo.at<int>(i) * scale) - 1;
|
||||
// canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast
|
||||
if (v >= 0)
|
||||
line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases) {
|
||||
assert(histos.size() == 3 &&
|
||||
histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S);
|
||||
|
||||
canvases.clear();
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histos[i], canvas, i);
|
||||
canvases.push_back(canvas.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::showHisto(Mat img, string title, int wait) {
|
||||
assert(img.type() == CV_8UC1 || img.type() == CV_8UC3);
|
||||
|
||||
if (img.type() == CV_8UC1) {
|
||||
Mat histo;
|
||||
Histo::calcHistoC1(img, histo);
|
||||
|
||||
// az ertekek konzolra iratasa
|
||||
//cout << histo << endl;
|
||||
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histo, canvas);
|
||||
imshow(title, canvas);
|
||||
}
|
||||
else if (img.type() == CV_8UC3) {
|
||||
vector<Mat> histos;
|
||||
Histo::calcHistoC3(img, histos);
|
||||
|
||||
vector<Mat> canvases;
|
||||
Histo::drawHistoC3(histos, canvases);
|
||||
|
||||
string str = "BGR";
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
imshow(title + "-" + str[i], canvases[i]);
|
||||
}
|
||||
}
|
||||
waitKey(wait);
|
||||
}
|
||||
32
ora6/proj3/histo.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
1 es 3 csatornas, csatornankent 8 bites kepekre:
|
||||
Histo::showHisto(img);
|
||||
*/
|
||||
#ifndef HISTO_H_
|
||||
#define HISTO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace Histo {
|
||||
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||
|
||||
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||
|
||||
/// <summary>
|
||||
/// Egy kep hisztogramjanak megjelenitese.
|
||||
/// </summary>
|
||||
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||
/// <param name="title">ablaknev</param>
|
||||
/// <param name="wait">varakoztatas</param>
|
||||
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif HISTO_H_
|
||||
26
ora6/proj3/main.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "histo.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(){
|
||||
Mat img = imread("dark_img.jpg", IMREAD_GRAYSCALE);
|
||||
imshow("img", img);
|
||||
Histo::showHisto(img);
|
||||
|
||||
double ah, fh;
|
||||
minMaxLoc(img, &ah, &fh);
|
||||
|
||||
fh = 30;
|
||||
|
||||
Mat dest = (ah == fh) ? img.clone() : (img-ah) * 255 / (fh-ah);
|
||||
|
||||
imshow("dest", dest);
|
||||
Histo::showHisto(dest, "eredmeny");
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
2
ora6/proj4/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora6/proj4/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4`
|
||||
LIBS = `pkg-config --libs opencv4`
|
||||
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
TARGET = main
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CXX) $(OBJ) -o $@ $(LIBS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
126
ora6/proj4/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "histo.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) {
|
||||
assert(img.type() == CV_8UC1);
|
||||
|
||||
// CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz.
|
||||
histo = Mat::zeros(256, 1, CV_32S);
|
||||
for (int i = 0; i < img.rows; i++)
|
||||
for (int j = 0; j < img.cols; j++)
|
||||
histo.at<int>(img.at<uchar>(i, j))++;
|
||||
}
|
||||
|
||||
|
||||
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||
assert(img.type() == CV_8UC3);
|
||||
|
||||
vector<Mat> chs;
|
||||
split(img.clone(), chs);
|
||||
|
||||
Mat h0, h1, h2;
|
||||
Histo::calcHistoC1(chs[0], h0);
|
||||
Histo::calcHistoC1(chs[1], h1);
|
||||
Histo::calcHistoC1(chs[2], h2);
|
||||
|
||||
histo_vect.clear();
|
||||
histo_vect.push_back(h0);
|
||||
histo_vect.push_back(h1);
|
||||
histo_vect.push_back(h2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) {
|
||||
assert(histo.type() == CV_32S);
|
||||
|
||||
int pad = 10;
|
||||
canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3);
|
||||
|
||||
// a hisztogram alatti szurke sav rajzolasa
|
||||
for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
if (0 <= channel && channel <= 2) {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||
}
|
||||
else {
|
||||
canvas.at<Vec3b>(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vec3b color(255, 255, 255);
|
||||
if (0 <= channel && channel <= 2) {
|
||||
color = Vec3b(0, 0, 0);
|
||||
color[channel] = 255;
|
||||
}
|
||||
|
||||
|
||||
double minv, maxv;
|
||||
minMaxLoc(histo, &minv, &maxv);
|
||||
|
||||
double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat
|
||||
|
||||
// a hisztogram rajzolasa
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
// egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1)
|
||||
int v = int(histo.at<int>(i) * scale) - 1;
|
||||
// canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast
|
||||
if (v >= 0)
|
||||
line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases) {
|
||||
assert(histos.size() == 3 &&
|
||||
histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S);
|
||||
|
||||
canvases.clear();
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histos[i], canvas, i);
|
||||
canvases.push_back(canvas.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Histo::showHisto(Mat img, string title, int wait) {
|
||||
assert(img.type() == CV_8UC1 || img.type() == CV_8UC3);
|
||||
|
||||
if (img.type() == CV_8UC1) {
|
||||
Mat histo;
|
||||
Histo::calcHistoC1(img, histo);
|
||||
|
||||
// az ertekek konzolra iratasa
|
||||
//cout << histo << endl;
|
||||
|
||||
Mat canvas;
|
||||
Histo::drawHistoC1(histo, canvas);
|
||||
imshow(title, canvas);
|
||||
}
|
||||
else if (img.type() == CV_8UC3) {
|
||||
vector<Mat> histos;
|
||||
Histo::calcHistoC3(img, histos);
|
||||
|
||||
vector<Mat> canvases;
|
||||
Histo::drawHistoC3(histos, canvases);
|
||||
|
||||
string str = "BGR";
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
imshow(title + "-" + str[i], canvases[i]);
|
||||
}
|
||||
}
|
||||
waitKey(wait);
|
||||
}
|
||||
32
ora6/proj4/histo.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||
1 es 3 csatornas, csatornankent 8 bites kepekre:
|
||||
Histo::showHisto(img);
|
||||
*/
|
||||
#ifndef HISTO_H_
|
||||
#define HISTO_H_
|
||||
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace Histo {
|
||||
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||
|
||||
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||
|
||||
/// <summary>
|
||||
/// Egy kep hisztogramjanak megjelenitese.
|
||||
/// </summary>
|
||||
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||
/// <param name="title">ablaknev</param>
|
||||
/// <param name="wait">varakoztatas</param>
|
||||
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif HISTO_H_
|
||||
26
ora6/proj4/main.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "histo.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(){
|
||||
Mat img = imread("dark_img.jpg", IMREAD_GRAYSCALE);
|
||||
imshow("img", img);
|
||||
Histo::showHisto(img);
|
||||
|
||||
double ah, fh;
|
||||
minMaxLoc(img, &ah, &fh);
|
||||
|
||||
fh = 30;
|
||||
|
||||
Mat dest = (ah == fh) ? img.clone() : (img-ah) * 255 / (fh-ah);
|
||||
|
||||
imshow("dest", dest);
|
||||
Histo::showHisto(dest, "eredmeny");
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
BIN
ora6/road.png
Normal file
|
After Width: | Height: | Size: 892 KiB |
BIN
ora6/sajt.png
Normal file
|
After Width: | Height: | Size: 690 KiB |
BIN
ora6/sajt_keskeny_keret.png
Normal file
|
After Width: | Height: | Size: 179 KiB |
BIN
ora6/smarties.jpg
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
ora6/swiss_cheese.jpg
Normal file
|
After Width: | Height: | Size: 394 KiB |
BIN
ora6/szitakoto.jpg
Normal file
|
After Width: | Height: | Size: 188 KiB |
BIN
ora6/wrench.jpg
Normal file
|
After Width: | Height: | Size: 96 KiB |