diff --git a/ora6/.clangd b/ora6/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora6/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora6/American_Eskimo_Dog.jpg b/ora6/American_Eskimo_Dog.jpg new file mode 100644 index 0000000..12f0e0d Binary files /dev/null and b/ora6/American_Eskimo_Dog.jpg differ diff --git a/ora6/Képek (morfológia)-20251030.zip b/ora6/Képek (morfológia)-20251030.zip new file mode 100644 index 0000000..f992280 Binary files /dev/null and b/ora6/Képek (morfológia)-20251030.zip differ diff --git a/ora6/Képek (élkeresés)-20251030.zip b/ora6/Képek (élkeresés)-20251030.zip new file mode 100644 index 0000000..af418d2 Binary files /dev/null and b/ora6/Képek (élkeresés)-20251030.zip differ diff --git a/ora6/Makefile b/ora6/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora6/Makefile @@ -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) diff --git a/ora6/annotalt_sejt.png b/ora6/annotalt_sejt.png new file mode 100644 index 0000000..46666e2 Binary files /dev/null and b/ora6/annotalt_sejt.png differ diff --git a/ora6/edges_noise.png b/ora6/edges_noise.png new file mode 100644 index 0000000..5dc42cf Binary files /dev/null and b/ora6/edges_noise.png differ diff --git a/ora6/galaxy.jpg b/ora6/galaxy.jpg new file mode 100644 index 0000000..8dcada4 Binary files /dev/null and b/ora6/galaxy.jpg differ diff --git a/ora6/go2.png b/ora6/go2.png new file mode 100644 index 0000000..cdf92a8 Binary files /dev/null and b/ora6/go2.png differ diff --git a/ora6/graycat.jpg b/ora6/graycat.jpg new file mode 100644 index 0000000..110a5cb Binary files /dev/null and b/ora6/graycat.jpg differ diff --git a/ora6/hela.zip b/ora6/hela.zip new file mode 100644 index 0000000..10b8499 Binary files /dev/null and b/ora6/hela.zip differ diff --git a/ora6/hela/0.png b/ora6/hela/0.png new file mode 100644 index 0000000..de63b87 Binary files /dev/null and b/ora6/hela/0.png differ diff --git a/ora6/hela/1.png b/ora6/hela/1.png new file mode 100644 index 0000000..efb2e45 Binary files /dev/null and b/ora6/hela/1.png differ diff --git a/ora6/hela/2.png b/ora6/hela/2.png new file mode 100644 index 0000000..c5ba84c Binary files /dev/null and b/ora6/hela/2.png differ diff --git a/ora6/hela/3.png b/ora6/hela/3.png new file mode 100644 index 0000000..a2627a4 Binary files /dev/null and b/ora6/hela/3.png differ diff --git a/ora6/hela/4.png b/ora6/hela/4.png new file mode 100644 index 0000000..f231bbc Binary files /dev/null and b/ora6/hela/4.png differ diff --git a/ora6/hela/5.png b/ora6/hela/5.png new file mode 100644 index 0000000..bcc45ce Binary files /dev/null and b/ora6/hela/5.png differ diff --git a/ora6/hela/6.png b/ora6/hela/6.png new file mode 100644 index 0000000..dc78d4d Binary files /dev/null and b/ora6/hela/6.png differ diff --git a/ora6/hela/7.png b/ora6/hela/7.png new file mode 100644 index 0000000..222f8ba Binary files /dev/null and b/ora6/hela/7.png differ diff --git a/ora6/hela/8.png b/ora6/hela/8.png new file mode 100644 index 0000000..0a887bd Binary files /dev/null and b/ora6/hela/8.png differ diff --git a/ora6/hela/9.png b/ora6/hela/9.png new file mode 100644 index 0000000..cbc5e95 Binary files /dev/null and b/ora6/hela/9.png differ diff --git a/ora6/histo.cpp b/ora6/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora6/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#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(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector 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(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(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(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 histos, vector& 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 histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora6/histo.h b/ora6/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora6/histo.h @@ -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 +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora6/labirintus.png b/ora6/labirintus.png new file mode 100644 index 0000000..e070d0c Binary files /dev/null and b/ora6/labirintus.png differ diff --git a/ora6/main.cpp b/ora6/main.cpp new file mode 100644 index 0000000..d20cd44 --- /dev/null +++ b/ora6/main.cpp @@ -0,0 +1,26 @@ +#include "histo.h" +#include +#include +#include +#include + +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; +} diff --git a/ora6/proj/.clangd b/ora6/proj/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora6/proj/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora6/proj/Makefile b/ora6/proj/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora6/proj/Makefile @@ -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) diff --git a/ora6/proj/histo.cpp b/ora6/proj/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora6/proj/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#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(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector 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(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(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(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 histos, vector& 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 histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora6/proj/histo.h b/ora6/proj/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora6/proj/histo.h @@ -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 +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora6/proj/histo.o b/ora6/proj/histo.o new file mode 100644 index 0000000..fceefea Binary files /dev/null and b/ora6/proj/histo.o differ diff --git a/ora6/proj/main b/ora6/proj/main new file mode 100755 index 0000000..3f8afbc Binary files /dev/null and b/ora6/proj/main differ diff --git a/ora6/proj/main.cpp b/ora6/proj/main.cpp new file mode 100644 index 0000000..43cb907 --- /dev/null +++ b/ora6/proj/main.cpp @@ -0,0 +1,46 @@ +#include "histo.h" +#include "opencv2/imgcodecs.hpp" +#include +#include +#include +#include + +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; +} diff --git a/ora6/proj/main.o b/ora6/proj/main.o new file mode 100644 index 0000000..bc3a102 Binary files /dev/null and b/ora6/proj/main.o differ diff --git a/ora6/proj1/.clangd b/ora6/proj1/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora6/proj1/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora6/proj1/Makefile b/ora6/proj1/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora6/proj1/Makefile @@ -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) diff --git a/ora6/proj1/histo.cpp b/ora6/proj1/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora6/proj1/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#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(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector 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(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(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(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 histos, vector& 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 histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora6/proj1/histo.h b/ora6/proj1/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora6/proj1/histo.h @@ -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 +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora6/proj1/histo.o b/ora6/proj1/histo.o new file mode 100644 index 0000000..fceefea Binary files /dev/null and b/ora6/proj1/histo.o differ diff --git a/ora6/proj1/main.cpp b/ora6/proj1/main.cpp new file mode 100644 index 0000000..5013886 --- /dev/null +++ b/ora6/proj1/main.cpp @@ -0,0 +1,67 @@ +#include "histo.h" +#include "opencv2/imgcodecs.hpp" +#include +#include +#include +#include + +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(i,j) = img.at(i,j) - img.at(i+1, j+1); + gy.at(i,j) = img.at(i,j+1) - img.at(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; +} diff --git a/ora6/proj2/.clangd b/ora6/proj2/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora6/proj2/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora6/proj2/Makefile b/ora6/proj2/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora6/proj2/Makefile @@ -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) diff --git a/ora6/proj2/histo.cpp b/ora6/proj2/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora6/proj2/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#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(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector 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(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(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(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 histos, vector& 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 histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora6/proj2/histo.h b/ora6/proj2/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora6/proj2/histo.h @@ -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 +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora6/proj2/main.cpp b/ora6/proj2/main.cpp new file mode 100644 index 0000000..e071fe0 --- /dev/null +++ b/ora6/proj2/main.cpp @@ -0,0 +1,14 @@ +#include "histo.h" +#include +#include +#include +#include + +using namespace cv; + +int main(){ + + + waitKey(); + return 0; +} diff --git a/ora6/proj3/.clangd b/ora6/proj3/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora6/proj3/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora6/proj3/Makefile b/ora6/proj3/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora6/proj3/Makefile @@ -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) diff --git a/ora6/proj3/histo.cpp b/ora6/proj3/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora6/proj3/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#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(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector 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(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(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(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 histos, vector& 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 histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora6/proj3/histo.h b/ora6/proj3/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora6/proj3/histo.h @@ -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 +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora6/proj3/main.cpp b/ora6/proj3/main.cpp new file mode 100644 index 0000000..d20cd44 --- /dev/null +++ b/ora6/proj3/main.cpp @@ -0,0 +1,26 @@ +#include "histo.h" +#include +#include +#include +#include + +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; +} diff --git a/ora6/proj4/.clangd b/ora6/proj4/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora6/proj4/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora6/proj4/Makefile b/ora6/proj4/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora6/proj4/Makefile @@ -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) diff --git a/ora6/proj4/histo.cpp b/ora6/proj4/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora6/proj4/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#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(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector 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(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(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(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 histos, vector& 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 histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora6/proj4/histo.h b/ora6/proj4/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora6/proj4/histo.h @@ -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 +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora6/proj4/main.cpp b/ora6/proj4/main.cpp new file mode 100644 index 0000000..d20cd44 --- /dev/null +++ b/ora6/proj4/main.cpp @@ -0,0 +1,26 @@ +#include "histo.h" +#include +#include +#include +#include + +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; +} diff --git a/ora6/road.png b/ora6/road.png new file mode 100644 index 0000000..b129600 Binary files /dev/null and b/ora6/road.png differ diff --git a/ora6/sajt.png b/ora6/sajt.png new file mode 100644 index 0000000..d6bc1fa Binary files /dev/null and b/ora6/sajt.png differ diff --git a/ora6/sajt_keskeny_keret.png b/ora6/sajt_keskeny_keret.png new file mode 100644 index 0000000..bdd248a Binary files /dev/null and b/ora6/sajt_keskeny_keret.png differ diff --git a/ora6/smarties.jpg b/ora6/smarties.jpg new file mode 100644 index 0000000..a7f2d30 Binary files /dev/null and b/ora6/smarties.jpg differ diff --git a/ora6/swiss_cheese.jpg b/ora6/swiss_cheese.jpg new file mode 100644 index 0000000..dc71b02 Binary files /dev/null and b/ora6/swiss_cheese.jpg differ diff --git a/ora6/szitakoto.jpg b/ora6/szitakoto.jpg new file mode 100644 index 0000000..c6e16ef Binary files /dev/null and b/ora6/szitakoto.jpg differ diff --git a/ora6/wrench.jpg b/ora6/wrench.jpg new file mode 100644 index 0000000..02b6821 Binary files /dev/null and b/ora6/wrench.jpg differ