before ora4
@@ -15,7 +15,7 @@ int main(){
|
|||||||
Mat d = Scalar(255, 255, 255) - img; //invertalas //bgr formatum
|
Mat d = Scalar(255, 255, 255) - img; //invertalas //bgr formatum
|
||||||
imshow("k", d);
|
imshow("k", d);
|
||||||
|
|
||||||
|
//ha egy kepnek modositani akarom a fejlecet akkor referenciakent kell atadni a fv-nek
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
ora2/main3
Executable file
32
ora2/main3.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Mat bg = imread("background.jpg", IMREAD_COLOR);
|
||||||
|
Mat fg = imread("kurama.jpg", IMREAD_COLOR);
|
||||||
|
|
||||||
|
if(bg.empty() || fg.empty()){
|
||||||
|
std::cout << "az egyik kep ures" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
resize(bg, bg, fg.size()); //bg atmeretezese az fg meretere
|
||||||
|
Mat u = fg.clone();
|
||||||
|
namedWindow("u", WINDOW_NORMAL);
|
||||||
|
imshow("u", u);
|
||||||
|
|
||||||
|
int value = 50;
|
||||||
|
createTrackbar("alfa", "u", &value, 100);
|
||||||
|
|
||||||
|
while(waitKey(1) != 'q'){
|
||||||
|
double a = value / 100.0; //0.5; //alpha, eloter vagy hatter latszodjon jobban
|
||||||
|
Mat u = a * bg + (1-a) * fg;
|
||||||
|
imshow("u", u);
|
||||||
|
}
|
||||||
|
|
||||||
|
waitKey();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ora2/main4
Executable file
47
ora2/main4.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Mat_<Vec3b> img = imread("kurama.jpg", IMREAD_COLOR); //ha itt meg van adva a templatebe a tipus akkor kesobb nem kella
|
||||||
|
|
||||||
|
//feher pontokat feketere:
|
||||||
|
//grayscale
|
||||||
|
/*for(int i = 0; i < img.rows; i++){
|
||||||
|
for(int j = 0; j < img.cols; j++){
|
||||||
|
if(img.at<uchar>(i,j) > 230){
|
||||||
|
img.at<uchar>(i,j) = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
Vec3b white(255,255,255);
|
||||||
|
Vec3b black(0,0,0);
|
||||||
|
|
||||||
|
for(int i = 0; i < img.rows; i++){
|
||||||
|
for(int j = 0; j < img.cols; j++){
|
||||||
|
/*if(img.at<Vec3b>(i,j)[0] > 230){ //[] melyik szin csatorna (bgr)
|
||||||
|
img.at<Vec3b>(i,j) = black;
|
||||||
|
}*/
|
||||||
|
//if(img(i,j)[0] > 230){
|
||||||
|
// img(i,j) = black;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto &p : img){
|
||||||
|
//csak akkor kell referencia ha modositani akarjuk
|
||||||
|
if(p[0] > 230){
|
||||||
|
p = black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
imshow("img", img);
|
||||||
|
|
||||||
|
waitKey();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ora2/main5
Executable file
25
ora2/main5.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Mat_<Vec3b> orange = imread("orange1.jpg", IMREAD_COLOR);
|
||||||
|
|
||||||
|
Vec3b black = Vec3b(0,0,0);
|
||||||
|
for(int i = 0; i < orange.rows; i++){
|
||||||
|
for(int j = 0; j < orange.cols; j++){
|
||||||
|
if(orange(i,j)[2] < 164 && !(orange(i,j)[1] < orange(i,j)[2])){
|
||||||
|
orange(i,j) = black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
imshow("img", orange);
|
||||||
|
|
||||||
|
waitKey();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ora2/orange1.jpg
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
ora3/Deik.jpg
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
ora3/Képek2-20250925.zip
Normal file
5
ora3/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CFLAGS = `pkg-config --cflags opencv4`
|
||||||
|
LIBS = `pkg-config --libs opencv4`
|
||||||
|
|
||||||
|
% : %.cpp
|
||||||
|
g++ $(CFLAGS) $(LIBS) -o $@ $<
|
||||||
126
ora3/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
ora3/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_
|
||||||
43
ora3/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Mat img = imread("milka.jpg", IMREAD_COLOR);
|
||||||
|
Mat hsv;
|
||||||
|
Mat dest;
|
||||||
|
Mat dest2;
|
||||||
|
|
||||||
|
cvtColor(img, hsv, COLOR_BGR2HSV);
|
||||||
|
Mat_<Vec3b> hs = hsv;
|
||||||
|
Vec3b c;
|
||||||
|
|
||||||
|
for(int i = 0; i < img.rows; i++){
|
||||||
|
for(int j = 0; j < img.cols; j++){
|
||||||
|
c = hsv.at<Vec3b>(i,j);
|
||||||
|
if(c[0] > 120){
|
||||||
|
hsv.at<Vec3b>(i,j)[0] = 0; //h csatornan mindent 0-ra szinezunk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& c : hs){
|
||||||
|
if(c[0] > 120){
|
||||||
|
c[0] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cvtColor(hsv, dest, COLOR_HSV2BGR);
|
||||||
|
cvtColor(hs, dest2, COLOR_HSV2BGR);
|
||||||
|
imshow("img", img);
|
||||||
|
imshow("hsv", dest);
|
||||||
|
imshow("hs", dest2);
|
||||||
|
|
||||||
|
|
||||||
|
waitKey();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ora3/main2
Executable file
36
ora3/main2.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
void convert(const Mat img, Mat& lab){
|
||||||
|
Mat imgf;
|
||||||
|
img.convertTo(imgf, CV_32FC3, 1/255.0); //tipus converzio rgb 0-1 tartomany
|
||||||
|
cvtColor(imgf, lab, COLOR_BGR2Lab);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Mat img = imread("mormota_kekhatter.jpg", IMREAD_COLOR);
|
||||||
|
Mat hsv, mask;
|
||||||
|
|
||||||
|
cvtColor(img, hsv, COLOR_BGR2HSV);
|
||||||
|
|
||||||
|
inRange(hsv, Scalar(80,0,0), Scalar(150,255,255), mask); //kek szin kiszurese, a tobbi csatornan mindent atengedunk
|
||||||
|
mask = 255 - mask; //invertalas
|
||||||
|
|
||||||
|
imshow("mask", mask);
|
||||||
|
imshow("img", img);
|
||||||
|
|
||||||
|
Mat img2 = imread("Deik.jpg", IMREAD_COLOR);
|
||||||
|
Rect rect(0, img2.rows -1-mask.rows, mask.cols, mask.rows);
|
||||||
|
img.copyTo(img2(rect), mask);
|
||||||
|
|
||||||
|
imshow("img2", img2);
|
||||||
|
|
||||||
|
waitKey();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ora3/main3
Executable file
64
ora3/main3.cpp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
|
||||||
|
void convert(const Mat img, Mat& lab){
|
||||||
|
Mat imgf;
|
||||||
|
img.convertTo(imgf, CV_32FC3, 1/255.0); //tipus converzio rgb 0-1 tartomany
|
||||||
|
cvtColor(imgf, lab, COLOR_BGR2Lab);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double avg_diff(const Mat lab1, const Mat lab2){
|
||||||
|
Mat diff = lab1 - lab2;
|
||||||
|
Mat diff2 = diff.mul(diff); //1 kep 3 csatornara: dL^2 dA^2 dB^2 ezeket kellene osszeadni
|
||||||
|
std::vector<Mat> chs;
|
||||||
|
split(diff2, chs); //3 kep 1 csatorna
|
||||||
|
|
||||||
|
Mat E;
|
||||||
|
cv::sqrt(chs[0] + chs[1] + chs[2], E);
|
||||||
|
|
||||||
|
return mean(E)[0]; //mivel osszeadtuk a skalarbol kivesszuk az elso erteket mert csak az a lenyeg
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_category(double diff){}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Mat etalon = imread("padlolapok/etalon.png", IMREAD_COLOR);
|
||||||
|
Mat elab;
|
||||||
|
|
||||||
|
convert(etalon, elab);
|
||||||
|
imshow("img", etalon);
|
||||||
|
moveWindow("img", 0,0);
|
||||||
|
|
||||||
|
|
||||||
|
/*Vec3f c1 = lab.at<Vec3f>(0,0);
|
||||||
|
Vec3f c2 = lab.at<Vec3f>(0,1);
|
||||||
|
|
||||||
|
std::cout<< c1 << " " << c2 << std::endl;
|
||||||
|
std::cout << "tavolsag: " << norm(c2-c1) << std::endl;
|
||||||
|
|
||||||
|
Vec3f c3 = lab.at<Vec3f>(lab.rows-1, lab.cols-1);
|
||||||
|
std::cout<< "tavolsag: " << norm(c3-c1) << std::endl;*/
|
||||||
|
|
||||||
|
for(int i = 1; i < 7; i++){
|
||||||
|
Mat img = imread("padlolapok/fa_" + std::to_string(i) + ".png", IMREAD_COLOR);
|
||||||
|
Mat lab;
|
||||||
|
|
||||||
|
convert(img, lab);
|
||||||
|
std::string name = "img" + std::to_string(i);
|
||||||
|
imshow(name, img);
|
||||||
|
|
||||||
|
moveWindow(name, 400, i*(img.rows+30));
|
||||||
|
|
||||||
|
std::cout << i << " " << avg_diff(elab, lab) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
waitKey();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ora3/milka.jpg
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
ora3/mormota_kekhatter.jpg
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
ora3/orange1.jpg
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
ora3/padlolapok.zip
Normal file
BIN
ora3/padlolapok/etalon.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
ora3/padlolapok/fa_1.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
ora3/padlolapok/fa_2.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
ora3/padlolapok/fa_3.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
ora3/padlolapok/fa_4.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
ora3/padlolapok/fa_5.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
ora3/padlolapok/fa_6.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
ora3/padlolapok/fa_7.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
ora4/KossuthSquare.zip
Normal file
BIN
ora4/Képek (képjavítás)-20250925.zip
Normal file
18
ora4/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
ora4/dark_img.jpg
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
ora4/debrecen_deep.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
126
ora4/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
ora4/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
ora4/histo.o
Normal file
24
ora4/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#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("debrecen_deep.png", IMREAD_GRAYSCALE);
|
||||||
|
imshow("img", img);
|
||||||
|
Histo::showHisto(img);
|
||||||
|
|
||||||
|
double ah, fh;
|
||||||
|
minMaxLoc(img, &ah, &fh);
|
||||||
|
|
||||||
|
Mat dest = (ah == fh) ? img.clone() : (img-ah) * 255 / (fh-ah);
|
||||||
|
|
||||||
|
imshow("dest", dest);
|
||||||
|
Histo::showHisto(dest);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ora4/main.o
Normal file
BIN
ora4/melyseg.png
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ora4/szines.png
Normal file
|
After Width: | Height: | Size: 1005 KiB |
BIN
ora4/szita2.png
Normal file
|
After Width: | Height: | Size: 65 KiB |