SlideShare a Scribd company logo
LAPORAN WORKSHOP KOMPUTER VISI
HISTOGRAM dan SEGMENTASI
LUSIANA DIYAN NINGRUM
2210181051
3 D4 TEKNIK KOMPUTER B
PRODI SARJANA TERAPAN TEKNIK KOMPUTER
DEPARTEMEN TEKNIK INFORMATIKA DAN KOMPUTER
POLITEKNIK ELEKTRONIKA NEGERI SURABAYA
SURABAYA
Histogram Gray Scale Image dari Sebuah File
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("histo3.JPG", CV_LOAD_IMAGE_COLOR); // Read the file
"image.jpg".
cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
imshow("Gray Scale Image", gray_frame);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist;
/// Compute the histograms:
calcHist(&gray_frame, 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
}
/// Display
imshow("Histogram of Gray Scale Image", histImage);
waitKey();
return EXIT_SUCCESS;
}
Image1
Image2
Image 3
Analisa
Berdasarkan hasil grafik image dapat diketahui bahwa semakin banyak bagian terang pada
suatu gambar, grafik akan cenderung tinggi di sebelah kanan, dan semakin banyak elemen
gelap dalam suatu gambar maka grafik akan cederung tinggi di sisi kiri. Hal ini dikarena
grafik di sebelah kiri merupakan warna hitam yang semakin ke kanan akan condong ke warna
putih, sehingga ketika suatu gambar memiliki banyak bagian yang cerah maka gambar
tersebut banyak memiliki elemen berwarna putih, sebaliknya gambar yang condong berwarna
gelap memiliki banyak elemen berwarna hitam.
Histogram Gray Scale Image dari Livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(0);
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get();
return -1;
}
while (1)
{
Mat frame, gray_frame;
cap >> frame;
cap.read(frame);
cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
char c = (char)waitKey(1);
if (c == 27)
break;
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist;
/// Compute the histograms:
calcHist(&gray_frame, 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
imshow("CAMERA", frame);
}
waitKey();
return EXIT_SUCCESS;
}
Analisa
Ketika kamera menangkap suatu gambar yang memiliki intensitas yang rendah (0,0,0) maka grafik
akan mengalami kenaikan dari sisi kiri dan semakin terang gambar tersebut maka angka kenaikan
grafik akan semakin ke kanan. Berdasarkan hasil percobaan ini, dapat diketahui bahwa intensitas
cahaya pada gambar cenderung terang tetapi gambar juga menangkap objek yang berwarna gelap
sehingga grafik menunjukkan kenaikan di sisi kiri dan kenaikan grafik yang signifikan berada di
sebelah kanan karena gambar memiliki banyak bagian yang cenderung terang sehingga data yang
terbaca oleh grafik mendekati kea rah intensitas yang tinggi sekitar 255.
Histogram RGB Image dari Livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(0);
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get();
return -1;
}
while (1)
{
Mat frame;
cap >> frame;
char c = (char)waitKey(1);
if (c == 27)
break;
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for each channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
imshow("CAMERA", frame);
}
waitKey();
return EXIT_SUCCESS;
}
Analisa
Komposisi warna pada gambar tersebut menunjukkan jika grafik mengalami kenaikan pada
intensitas yang rendah (0,0,0) karena pada gambar yang terbaca oleh kamera menangkap objek
yang berwarna gelap, sehingga grafik RGB mengalami kenaikan yang cukup tinggi yang berarti
bahwa pada intensitas tersebut mengalami percampuran ketiga warna yang cukup tinggi untuk
menghasilkan objek berwarna gelap. Sama halnya dengan sisi lain dari gambar tersebut yang
memiliki intensitas yang tinggi yakni mendekati nilai 255 karena camera menangkap objek yang
berwarna terang dengan environment lighting yang cukup bagus sehingga grafik mulai mengalami
kenaikan pada nilai tengah yang berada di sekitar intensitas 128 yang berarti bahwa percampuran
warna dominan putih atau warna cerah cukup tinggi untuk menghasilkan sisi bagian yang berwarna
terang pada gambar. Sehingga, ketika kamera menangkap objek kertas yang berwarna putih, grafik
akan mengalami kenaikan yang tinggi pada intensitas nilai 255 sedangkan pada intensitas yang
rendah (0,0,0) mengalami kelandaian grafik.
Histogram RGB Image dari Image
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("histo3.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg".
imshow("RGB Image", frame);
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
imshow("RGB Histogram of Gray Scale Image", histImage);
imshow("Original Image", frame);
waitKey();
return EXIT_SUCCESS;
}
Image1
Image2
Image3
Analisa
Grafik pada image1 menunjukkan kenaikan yang tinggi pada sisi kiri karena gambar yang memiliki
warna gelap sehingga percampuran warna RGB pada intensitas rendah cukup tinggi untuk
menghasilkan warna gelap tersebut. Seperti halnya pada hasil pembacaan image2 yang memiliki
sisi gelap tetapi ada sedikit dari gambar yang memiliki warna terang sehingga yang tergambar di
grafik cukup merata yakni pada nilai intensitas 0 – 128, hal ini juga terlihat pada grafik hasil
pembacaan image3 dimana gambar tersebut memilik warna yang terang sehingga grafik
menunjukkan kenaikan pada intensitas 128 – 255 yang berarti bahwa perpaduan warna RGB
dengan intensitas 128 – 255 cukup tinggi untuk menghasilkan gambar yang berwarna terang
tersebut. Hal ini terbukti pada hasil pembacaan grafik biru yang mengalami kenaikan paling tinggi
pada intensitas 255 karena gambar memiliki warna terang yang menunjukkan objek langit dengan
warna biru.
Histogram Equalization
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
using std::cout;
int main(int argc, char** argv)
{
//memulai capture video
VideoCapture cap(0);
if (!cap.isOpened())
return -1;
//mendapatkan nilai dimensi video, disimpan dalam variabel, ditampilkan
int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
printf("row %dn", frame_width);
printf("coloumn %dn", frame_height);
for (;;)
{
Mat frame; Mat hsv;
cap >> frame;
imshow("Frame", frame);
if (waitKey(30) >= 0)
break;
cap.read(frame);
cvtColor(frame, frame, COLOR_BGR2GRAY);
Mat dst;
equalizeHist(frame, dst);
imshow("Source image", frame);
imshow("Equalized Image", dst);
if (frame.empty())
{
cout << "ERROR blank framen";
break;
}
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat hist;
/// Compute the histograms:
calcHist(&frame, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform,
accumulate
);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(hist.at<float>(i
- 1))),
Point(bin_w*(i), hist_h - cvRound(hist.at<float>(i))),
Scalar(255, 255, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
}
return 0;
}
Analisa
Pada gambar histogram equalization jarak graylevel memiliki rentang antaranilai warna satu dengan
lainnya terdapat jarak yang cukup lebar yaitu artinya semakinsering/ intensitas greylevel yang
muncul itu tinggi. Histogram Equalization bertujuan mengubah pemetaan greylevel agar
sebarannya lebih menyebar pada kisaran 0 - 255, sehingga setiap derajat keabuan memiliki jumlah
pixel yang relatif sama.
Histogram Equalization Greyscale Mode Livecamera
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
using std::cout;
int sourceHist(Mat frame) {
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat histsrc;
/// Compute the histograms:
calcHist(&frame, 1, 0, Mat(), histsrc, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histSrc(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histSrc.rows ]
normalize(histsrc, histsrc, 0, histSrc.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histSrc, Point(bin_w * (i - 1), hist_h -
cvRound(histsrc.at<float>(i - 1))),
Point(bin_w * (i), hist_h -
cvRound(histsrc.at<float>(i))),
Scalar(255, 255, 255), 2, 8, 0);
}
namedWindow("Source histogram", CV_WINDOW_AUTOSIZE);
imshow("Source histogram", histSrc);
return 0;
}
int main(int argc, char** argv)
{
//memulai capture video
VideoCapture cap(0);
if (!cap.isOpened())
return -1;
//mendapatkan nilai dimensi video, disimpan dalam variabel, ditampilkan
int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
printf("row %dn", frame_width);
printf("coloumn %dn", frame_height);
for (;;)
{
Mat frame; Mat hsv;
cap >> frame;
//imshow("Frame", frame); //gambar asli
if (waitKey(30) >= 0)
break;
cap.read(frame);
cvtColor(frame, frame, COLOR_BGR2GRAY);
Mat dst;
equalizeHist(frame, dst);
imshow("Source image", frame); //gray scale
imshow("Equalized Image", dst); //equalized
if (frame.empty())
{
cout << "ERROR blank framen";
break;
}
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat hist; //srchist;
/// Compute the histograms:
calcHist(&dst, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform,
accumulate);
//calcHist(&frame, 1, 0, Mat(), srchist, 1, &histSize, &histRange, uniform,
accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
//Mat histSrc(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
//normalize(srchist, srchist, 0, histSrc.rows, NORM_MINMAX, -1, Mat());
/// Draw for channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w * (i - 1), hist_h -
cvRound(hist.at<float>(i - 1))),
Point(bin_w * (i), hist_h - cvRound(hist.at<float>(i))),
Scalar(255, 255, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
sourceHist(frame);
}
return 0;
}
Analisa
Histogram equalization merupakan metode perbaikan kualitas citra yang bertujuan untuk meratakan
persebaran nilai intensitas piksel suatu citra. Hal ini terlihat pada grafik dari gambar asli yang
belum mengalamu ekualisasi, persebaran nilai piksel nya masih terfokus pada rentang nilai 0 – 128
karena objek yang tertangkap kamera memiliki intensitas cahaya yang cukup serta adanya obje
yang berwarna gelap. Tetapi ketika sudah mengalami ekualifikasi pada gambar, data pembacaan
grafik menunjukkan persebarang nilai intensitas piksel yang merata dari rentang 0 – 255 yang
berarti bahwa gambar yang telah mengalami ekualifikasi mendapatkan perbaikan kualitas dari citra
image sehingga persebaran nilai intensitas piksel pada image tersebut lebih merata.
Histogram Equalization RGB dari Original livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int RGB_grafik(Mat frame) {
Mat b_hist, g_hist, r_hist;
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform,
accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform,
accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform,
accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for each channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
namedWindow("RGB histogram", CV_WINDOW_AUTOSIZE);
imshow("RGB histogram", histImage);
return 0;
}
int main(int argc, char* argv[])
{
//int RGB_grafik(frame);
//Open the video file for reading
VideoCapture cap(0);
// if not success, exit the program
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get(); //wait for any key press
return -1;
}
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat hist;
//Define the names of windows
String windowNameOfOriginalImage = "Original Video";
String windowNameOfHistogramEqualized = "Histogram Equalized Video";
// Create windows with the above names
namedWindow(windowNameOfOriginalImage, WINDOW_NORMAL);
namedWindow(windowNameOfHistogramEqualized, WINDOW_NORMAL);
while (true)
{
Mat frame;
bool bSuccess = cap.read(frame); // Read a new frame from the video file
//Breaking the while loop at the end of the video
if (bSuccess == false)
{
cout << "Found the end of the video" << endl;
break;
}
//Convert the frame from BGR to YCrCb color space
Mat hist_equalized_image;
cvtColor(frame, hist_equalized_image, COLOR_BGR2YCrCb);
//Split the image into 3 channels; Y, Cr and Cb channels respectively and
store it in a std::vector
vector<Mat> vec_channels;
split(hist_equalized_image, vec_channels);
//Equalize the histogram of the Y channel
equalizeHist(vec_channels[0], vec_channels[0]);
//Merge 3 channels in the std::vector to form the color image in YCrCB color
space.
merge(vec_channels, hist_equalized_image);
//Convert the histogram equalized image from YCrCb to BGR color space again
cvtColor(hist_equalized_image, hist_equalized_image, COLOR_YCrCb2BGR);
Mat b_hist, g_hist, r_hist;
calcHist(&vec_channels[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&vec_channels[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&vec_channels[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
//show frames in the created windows
imshow(windowNameOfOriginalImage, frame);
imshow(windowNameOfHistogramEqualized, hist_equalized_image);
imshow("calcHist Demo", histImage);
RGB_grafik(frame);
if (waitKey(5) == 27)
{
cout << "Esc key is pressed by the user. Stopping the video" << endl;
break;
}
}
destroyAllWindows(); //Destroy all opened windows
return 0;
}
Analisa
Melihat tujuan dari histogram equalization yang merupakan metode perbaikan kualitas citra untuk
meratakan persebaran nilai intensitas piksel suatu citra. Hal ini terlihat pada grafik dari gambar asli
dari livecam yang belum mengalami ekualisasi, persebaran nilai piksel RGB nya masih terfokus
pada rentang nilai 0 – 128 karena objek yang tertangkap kamera memiliki intensitas cahaya yang
cukup serta adanya objek yang berwarna gelap sehingga perpaduan warna RGB nya juga berada
pada rentang nilai 0 – 128. Tetapi ketika sudah mengalami ekualifikasi pada gambar, data
pembacaan grafik menunjukkan persebarang nilai intensitas piksel yang merata dari rentang 0 – 255
yang berarti bahwa gambar yang telah mengalami ekualifikasi mendapatkan perbaikan kualitas dari
citra image sehingga persebaran nilai intensitas piksel pada image tersebut lebih merata. Terutama
pada warna biru yang memiliki persebaran merata dari rentang nilai 0 – 255 dibandingkan
persebaran warna merah dan hijau yang masih berada pada rentang nilai 128.
SEGMENTASI
1. Histogram RGB Image dari Image File
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg".
//imshow("RGB Image", frame);
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
imshow("RGB Histogram Image", histImage);
imshow("Original Image", frame);
waitKey();
return EXIT_SUCCESS;
}
2. Hasil gambar intensitas R > 125
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg".
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 125, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
imshow("RGB Histogram Image", histImage);
imshow("Original Image", frame);
waitKey();
return EXIT_SUCCESS;
}
Analisa
Segmentasi merupakan proses pemisahan latar depan – latar belakang suatu image. Untuk case
pada soal ini dimana kami diminta untuk menampilkan grafik dari warna merah yang memiliki nilai
intensitas R lebih dari 125, sehingga pada variabel array yang digunakan untuk menampung nilai
dari warna diubah dengan nilai pada rentang 126 – 255 yang pada grafik menghasilkan klaster
warna merah yang memiliki intensitas pada rentang 126 – 255 dengan kerapatan yang cukup stabil.
Hal ini dikarenakan pada pemetaan warna citra dari image masukan dikelompokkan sesuai dengan
kesamaan warna yang dimiliki oleh objek pada gambar. Setiap piksel citra dikonversi dalam suatu
garis vector RGB untuk selanjutnya ditampilkan berdasarkan rata – rata dari kelompok warna yang
dihasilkan.
Menampilkan Warna Merah Saja dari Image
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame;
frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR);
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/*
Mat redOnly, mask;
Mat hsv_image;
cvtColor(frame, hsv_image, COLOR_BGR2HSV);
inRange(hsv_image, Scalar(0, 120, 70), Scalar(10, 255, 255), mask);
*/
Mat g, output;
g = Mat::zeros(Size(frame.cols, frame.rows), CV_8UC1);
// Showing Red Channel
// G and B channels are kept as zero matrix for visual perception
vector<Mat> channels;
channels.push_back(g);
channels.push_back(g);
channels.push_back(bgr_planes[2] > 125);
/// Merge the three channels
merge(channels, output);
namedWindow("Red", 1);
///Converting image from BGR to HSV color space.
Mat hsv_image;
cvtColor(frame, hsv_image, COLOR_BGR2HSV);
/// Creating masks to detect the upper and lower red color.
Mat mask1, mask2, red_output;
inRange(hsv_image, Scalar(0, 40, 30), Scalar(10, 255, 255), mask1);
//inRange(hsv_image, Scalar(130, 120, 120), Scalar(180, 255, 255), mask2);
// Generating the final mask
//mask1 = mask1 + mask2;
bitwise_and(frame, frame, red_output, mask1);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform,
accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform,
accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform,
accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for each channel
for (int i = 1; i < histSize; i++)
{
line(histImage,
Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage,
Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage,
Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
imshow("Image", frame);
imshow("Red", output);
imshow("Red Only", red_output);
waitKey();
return EXIT_SUCCESS;
}
Segmentasi pada suatu citra ( image segmentation) merupakan langkah awal pada proses analisa
citra yang bertujuan untuk mengambil informasi yang terdapat di dalam suatu citra. Segmentasi
citra membagi suatu citra ke dalam bagian-bagian atau objek-objek tertentu. Sampai sejauh
mana pembagian tersebut dilakukan tergantung pada masalah yang dihadapi. Idealnya, langkah
segmentasi tersebut dihentikan pada saat objek yang diinginkan sudah berhasil dipisahkan. Pada
kasus diatas, dari sampul buku terlebih dahulu dipisahkan dengan trasholding untuk mengetahui
dan memisahkan warna merah. Setelah warna merah sudah dapat diketahui selanjutnya bagian yang
selain warna merah dihitankan atau dihapus.

More Related Content

What's hot

Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
Andrey Karpov
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
Mr. Vengineer
 
【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks
Takeo Imai
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricksdutor
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
Andrey Karpov
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogramming
cppfrug
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
Egor Bogatov
 
What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++
Microsoft
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Sergey Platonov
 
OpenGL L03-Utilities
OpenGL L03-UtilitiesOpenGL L03-Utilities
OpenGL L03-Utilities
Mohammad Shaker
 
Python grass
Python grassPython grass
Python grass
Margherita Di Leo
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
Kim Phillips
 
C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략 C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략
명신 김
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
PyData
 
Introduction to Data Oriented Design
Introduction to Data Oriented DesignIntroduction to Data Oriented Design
Introduction to Data Oriented Design
Electronic Arts / DICE
 
A Step Towards Data Orientation
A Step Towards Data OrientationA Step Towards Data Orientation
A Step Towards Data Orientation
Electronic Arts / DICE
 
Yampa AFRP Introduction
Yampa AFRP IntroductionYampa AFRP Introduction
Yampa AFRP Introduction
ChengHui Weng
 

What's hot (20)

Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
 
【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogramming
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
 
OpenMP
OpenMPOpenMP
OpenMP
 
OpenGL L03-Utilities
OpenGL L03-UtilitiesOpenGL L03-Utilities
OpenGL L03-Utilities
 
Python grass
Python grassPython grass
Python grass
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
 
C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략 C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
 
user2015 keynote talk
user2015 keynote talkuser2015 keynote talk
user2015 keynote talk
 
Introduction to Data Oriented Design
Introduction to Data Oriented DesignIntroduction to Data Oriented Design
Introduction to Data Oriented Design
 
A Step Towards Data Orientation
A Step Towards Data OrientationA Step Towards Data Orientation
A Step Towards Data Orientation
 
Yampa AFRP Introduction
Yampa AFRP IntroductionYampa AFRP Introduction
Yampa AFRP Introduction
 

Similar to Histogram dan Segmentasi

A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processingChu Lam
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
antiw
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
GCS2013
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
aryan532920
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
OpenCVの基礎
OpenCVの基礎OpenCVの基礎
OpenCVの基礎
領一 和泉田
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
Platonov Sergey
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
Mark Billinghurst
 
Anomalies in X-Ray Engine
Anomalies in X-Ray EngineAnomalies in X-Ray Engine
Anomalies in X-Ray Engine
PVS-Studio
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prod
Yunong Xiao
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
shehabhamad_90
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
Remy Sharp
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
Fred Chien
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
PVS-Studio
 

Similar to Histogram dan Segmentasi (20)

Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processing
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Histogram
HistogramHistogram
Histogram
 
OpenCVの基礎
OpenCVの基礎OpenCVの基礎
OpenCVの基礎
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
 
Anomalies in X-Ray Engine
Anomalies in X-Ray EngineAnomalies in X-Ray Engine
Anomalies in X-Ray Engine
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prod
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
 

More from Lusiana Diyan

Komunikasi Bisnis yang Efektif
Komunikasi Bisnis yang EfektifKomunikasi Bisnis yang Efektif
Komunikasi Bisnis yang Efektif
Lusiana Diyan
 
Berkomunikasi dalam Tim
Berkomunikasi dalam TimBerkomunikasi dalam Tim
Berkomunikasi dalam Tim
Lusiana Diyan
 
Berkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan KeragamanBerkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan Keragaman
Lusiana Diyan
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan Bisnis
Lusiana Diyan
 
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan BisnisKemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Lusiana Diyan
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan Bisnis
Lusiana Diyan
 
Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3
Lusiana Diyan
 
Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2
Lusiana Diyan
 
Vocabulary Engineering Enrichment
Vocabulary Engineering EnrichmentVocabulary Engineering Enrichment
Vocabulary Engineering Enrichment
Lusiana Diyan
 
DESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENTDESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENT
Lusiana Diyan
 
Tutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan CoppeliasimTutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan Coppeliasim
Lusiana Diyan
 
CRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQLCRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQL
Lusiana Diyan
 
Kontrol LED melalui Web Server
Kontrol LED melalui Web ServerKontrol LED melalui Web Server
Kontrol LED melalui Web Server
Lusiana Diyan
 
Installasi NodeMCU
Installasi NodeMCUInstallasi NodeMCU
Installasi NodeMCU
Lusiana Diyan
 
Akses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry PiAkses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry Pi
Lusiana Diyan
 
Building A Simple Robot in VREP
Building A Simple Robot in VREPBuilding A Simple Robot in VREP
Building A Simple Robot in VREP
Lusiana Diyan
 
Tutorial Menggunakan Software Eagle
Tutorial Menggunakan Software EagleTutorial Menggunakan Software Eagle
Tutorial Menggunakan Software Eagle
Lusiana Diyan
 
Proses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat LunakProses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat Lunak
Lusiana Diyan
 
Produk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat LunakProduk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat Lunak
Lusiana Diyan
 
Open Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DCOpen Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DC
Lusiana Diyan
 

More from Lusiana Diyan (20)

Komunikasi Bisnis yang Efektif
Komunikasi Bisnis yang EfektifKomunikasi Bisnis yang Efektif
Komunikasi Bisnis yang Efektif
 
Berkomunikasi dalam Tim
Berkomunikasi dalam TimBerkomunikasi dalam Tim
Berkomunikasi dalam Tim
 
Berkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan KeragamanBerkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan Keragaman
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan Bisnis
 
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan BisnisKemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan Bisnis
 
Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3
 
Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2
 
Vocabulary Engineering Enrichment
Vocabulary Engineering EnrichmentVocabulary Engineering Enrichment
Vocabulary Engineering Enrichment
 
DESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENTDESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENT
 
Tutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan CoppeliasimTutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan Coppeliasim
 
CRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQLCRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQL
 
Kontrol LED melalui Web Server
Kontrol LED melalui Web ServerKontrol LED melalui Web Server
Kontrol LED melalui Web Server
 
Installasi NodeMCU
Installasi NodeMCUInstallasi NodeMCU
Installasi NodeMCU
 
Akses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry PiAkses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry Pi
 
Building A Simple Robot in VREP
Building A Simple Robot in VREPBuilding A Simple Robot in VREP
Building A Simple Robot in VREP
 
Tutorial Menggunakan Software Eagle
Tutorial Menggunakan Software EagleTutorial Menggunakan Software Eagle
Tutorial Menggunakan Software Eagle
 
Proses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat LunakProses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat Lunak
 
Produk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat LunakProduk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat Lunak
 
Open Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DCOpen Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DC
 

Recently uploaded

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 

Recently uploaded (20)

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 

Histogram dan Segmentasi

  • 1. LAPORAN WORKSHOP KOMPUTER VISI HISTOGRAM dan SEGMENTASI LUSIANA DIYAN NINGRUM 2210181051 3 D4 TEKNIK KOMPUTER B PRODI SARJANA TERAPAN TEKNIK KOMPUTER DEPARTEMEN TEKNIK INFORMATIKA DAN KOMPUTER POLITEKNIK ELEKTRONIKA NEGERI SURABAYA SURABAYA
  • 2. Histogram Gray Scale Image dari Sebuah File #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat frame, gray_frame; frame = imread("histo3.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg". cvtColor(frame, gray_frame, COLOR_BGR2GRAY); imshow("Gray Scale Image", gray_frame); /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat b_hist; /// Compute the histograms: calcHist(&gray_frame, 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw Histogram for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); } /// Display imshow("Histogram of Gray Scale Image", histImage); waitKey(); return EXIT_SUCCESS; }
  • 3. Image1 Image2 Image 3 Analisa Berdasarkan hasil grafik image dapat diketahui bahwa semakin banyak bagian terang pada suatu gambar, grafik akan cenderung tinggi di sebelah kanan, dan semakin banyak elemen gelap dalam suatu gambar maka grafik akan cederung tinggi di sisi kiri. Hal ini dikarena grafik di sebelah kiri merupakan warna hitam yang semakin ke kanan akan condong ke warna putih, sehingga ketika suatu gambar memiliki banyak bagian yang cerah maka gambar tersebut banyak memiliki elemen berwarna putih, sebaliknya gambar yang condong berwarna gelap memiliki banyak elemen berwarna hitam.
  • 4. Histogram Gray Scale Image dari Livecam #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { VideoCapture cap(0); if (cap.isOpened() == false) { cout << "Cannot open the video file" << endl; cin.get(); return -1; } while (1) { Mat frame, gray_frame; cap >> frame; cap.read(frame); cvtColor(frame, gray_frame, COLOR_BGR2GRAY); char c = (char)waitKey(1); if (c == 27) break; /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat b_hist; /// Compute the histograms: calcHist(&gray_frame, 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw Histogram for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); } /// Display namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE); imshow("calcHist Demo", histImage); imshow("CAMERA", frame); } waitKey(); return EXIT_SUCCESS; }
  • 5. Analisa Ketika kamera menangkap suatu gambar yang memiliki intensitas yang rendah (0,0,0) maka grafik akan mengalami kenaikan dari sisi kiri dan semakin terang gambar tersebut maka angka kenaikan grafik akan semakin ke kanan. Berdasarkan hasil percobaan ini, dapat diketahui bahwa intensitas cahaya pada gambar cenderung terang tetapi gambar juga menangkap objek yang berwarna gelap sehingga grafik menunjukkan kenaikan di sisi kiri dan kenaikan grafik yang signifikan berada di sebelah kanan karena gambar memiliki banyak bagian yang cenderung terang sehingga data yang terbaca oleh grafik mendekati kea rah intensitas yang tinggi sekitar 255. Histogram RGB Image dari Livecam #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { VideoCapture cap(0); if (cap.isOpened() == false) { cout << "Cannot open the video file" << endl; cin.get(); return -1; } while (1) { Mat frame; cap >> frame; char c = (char)waitKey(1); if (c == 27) break; /// Separate the image in 3 places ( B, G and R )
  • 6. vector<Mat> bgr_planes; split(frame, bgr_planes); /// Establish the number of bins int histSize = 256; /// Set the ranges ( for B,G,R) ) float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat b_hist, g_hist, r_hist; /// Compute the histograms: calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms for B, G and R int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw for each channel for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))), Scalar(0, 255, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255), 2, 8, 0); } /// Display namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE); imshow("calcHist Demo", histImage); imshow("CAMERA", frame); } waitKey(); return EXIT_SUCCESS; }
  • 7. Analisa Komposisi warna pada gambar tersebut menunjukkan jika grafik mengalami kenaikan pada intensitas yang rendah (0,0,0) karena pada gambar yang terbaca oleh kamera menangkap objek yang berwarna gelap, sehingga grafik RGB mengalami kenaikan yang cukup tinggi yang berarti bahwa pada intensitas tersebut mengalami percampuran ketiga warna yang cukup tinggi untuk menghasilkan objek berwarna gelap. Sama halnya dengan sisi lain dari gambar tersebut yang memiliki intensitas yang tinggi yakni mendekati nilai 255 karena camera menangkap objek yang berwarna terang dengan environment lighting yang cukup bagus sehingga grafik mulai mengalami kenaikan pada nilai tengah yang berada di sekitar intensitas 128 yang berarti bahwa percampuran warna dominan putih atau warna cerah cukup tinggi untuk menghasilkan sisi bagian yang berwarna terang pada gambar. Sehingga, ketika kamera menangkap objek kertas yang berwarna putih, grafik akan mengalami kenaikan yang tinggi pada intensitas nilai 255 sedangkan pada intensitas yang rendah (0,0,0) mengalami kelandaian grafik. Histogram RGB Image dari Image #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat frame, gray_frame; frame = imread("histo3.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg". imshow("RGB Image", frame); /// Separate the image in 3 places ( B, G and R ) vector<Mat> bgr_planes; split(frame, bgr_planes); /// Establish the number of bins int histSize = 256; /// Set the ranges
  • 8. float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat b_hist, g_hist, r_hist; /// Compute the histograms: calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms for B, G and R int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw Histogram for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))), Scalar(0, 255, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255), 2, 8, 0); } /// Display imshow("RGB Histogram of Gray Scale Image", histImage); imshow("Original Image", frame); waitKey(); return EXIT_SUCCESS; } Image1
  • 9. Image2 Image3 Analisa Grafik pada image1 menunjukkan kenaikan yang tinggi pada sisi kiri karena gambar yang memiliki warna gelap sehingga percampuran warna RGB pada intensitas rendah cukup tinggi untuk menghasilkan warna gelap tersebut. Seperti halnya pada hasil pembacaan image2 yang memiliki sisi gelap tetapi ada sedikit dari gambar yang memiliki warna terang sehingga yang tergambar di grafik cukup merata yakni pada nilai intensitas 0 – 128, hal ini juga terlihat pada grafik hasil pembacaan image3 dimana gambar tersebut memilik warna yang terang sehingga grafik menunjukkan kenaikan pada intensitas 128 – 255 yang berarti bahwa perpaduan warna RGB dengan intensitas 128 – 255 cukup tinggi untuk menghasilkan gambar yang berwarna terang tersebut. Hal ini terbukti pada hasil pembacaan grafik biru yang mengalami kenaikan paling tinggi pada intensitas 255 karena gambar memiliki warna terang yang menunjukkan objek langit dengan warna biru. Histogram Equalization #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream>
  • 10. using namespace std; using namespace cv; using std::cout; int main(int argc, char** argv) { //memulai capture video VideoCapture cap(0); if (!cap.isOpened()) return -1; //mendapatkan nilai dimensi video, disimpan dalam variabel, ditampilkan int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH); int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); printf("row %dn", frame_width); printf("coloumn %dn", frame_height); for (;;) { Mat frame; Mat hsv; cap >> frame; imshow("Frame", frame); if (waitKey(30) >= 0) break; cap.read(frame); cvtColor(frame, frame, COLOR_BGR2GRAY); Mat dst; equalizeHist(frame, dst); imshow("Source image", frame); imshow("Equalized Image", dst); if (frame.empty()) { cout << "ERROR blank framen"; break; } /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat hist; /// Compute the histograms: calcHist(&frame, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate ); // Draw the histograms int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw for channel for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(hist.at<float>(i))), Scalar(255, 255, 255), 2, 8, 0); } /// Display namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
  • 11. imshow("calcHist Demo", histImage); } return 0; } Analisa Pada gambar histogram equalization jarak graylevel memiliki rentang antaranilai warna satu dengan lainnya terdapat jarak yang cukup lebar yaitu artinya semakinsering/ intensitas greylevel yang muncul itu tinggi. Histogram Equalization bertujuan mengubah pemetaan greylevel agar sebarannya lebih menyebar pada kisaran 0 - 255, sehingga setiap derajat keabuan memiliki jumlah pixel yang relatif sama. Histogram Equalization Greyscale Mode Livecamera #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp"
  • 12. #include <iostream> using namespace std; using namespace cv; using std::cout; int sourceHist(Mat frame) { /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat histsrc; /// Compute the histograms: calcHist(&frame, 1, 0, Mat(), histsrc, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histSrc(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histSrc.rows ] normalize(histsrc, histsrc, 0, histSrc.rows, NORM_MINMAX, -1, Mat()); /// Draw Histogram for (int i = 1; i < histSize; i++) { line(histSrc, Point(bin_w * (i - 1), hist_h - cvRound(histsrc.at<float>(i - 1))), Point(bin_w * (i), hist_h - cvRound(histsrc.at<float>(i))), Scalar(255, 255, 255), 2, 8, 0); } namedWindow("Source histogram", CV_WINDOW_AUTOSIZE); imshow("Source histogram", histSrc); return 0; } int main(int argc, char** argv) { //memulai capture video VideoCapture cap(0); if (!cap.isOpened()) return -1; //mendapatkan nilai dimensi video, disimpan dalam variabel, ditampilkan int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH); int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); printf("row %dn", frame_width); printf("coloumn %dn", frame_height); for (;;) { Mat frame; Mat hsv; cap >> frame; //imshow("Frame", frame); //gambar asli if (waitKey(30) >= 0) break; cap.read(frame); cvtColor(frame, frame, COLOR_BGR2GRAY); Mat dst; equalizeHist(frame, dst); imshow("Source image", frame); //gray scale
  • 13. imshow("Equalized Image", dst); //equalized if (frame.empty()) { cout << "ERROR blank framen"; break; } /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat hist; //srchist; /// Compute the histograms: calcHist(&dst, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate); //calcHist(&frame, 1, 0, Mat(), srchist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); //Mat histSrc(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); //normalize(srchist, srchist, 0, histSrc.rows, NORM_MINMAX, -1, Mat()); /// Draw for channel for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w * (i - 1), hist_h - cvRound(hist.at<float>(i - 1))), Point(bin_w * (i), hist_h - cvRound(hist.at<float>(i))), Scalar(255, 255, 255), 2, 8, 0); } /// Display namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE); imshow("calcHist Demo", histImage); sourceHist(frame); } return 0; }
  • 14. Analisa Histogram equalization merupakan metode perbaikan kualitas citra yang bertujuan untuk meratakan persebaran nilai intensitas piksel suatu citra. Hal ini terlihat pada grafik dari gambar asli yang belum mengalamu ekualisasi, persebaran nilai piksel nya masih terfokus pada rentang nilai 0 – 128 karena objek yang tertangkap kamera memiliki intensitas cahaya yang cukup serta adanya obje yang berwarna gelap. Tetapi ketika sudah mengalami ekualifikasi pada gambar, data pembacaan grafik menunjukkan persebarang nilai intensitas piksel yang merata dari rentang 0 – 255 yang berarti bahwa gambar yang telah mengalami ekualifikasi mendapatkan perbaikan kualitas dari citra image sehingga persebaran nilai intensitas piksel pada image tersebut lebih merata. Histogram Equalization RGB dari Original livecam #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int RGB_grafik(Mat frame) { Mat b_hist, g_hist, r_hist; int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; /// Separate the image in 3 places ( B, G and R ) vector<Mat> bgr_planes; split(frame, bgr_planes); calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate);
  • 15. // Draw the histograms for B, G and R int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw for each channel for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))), Scalar(0, 255, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255), 2, 8, 0); } namedWindow("RGB histogram", CV_WINDOW_AUTOSIZE); imshow("RGB histogram", histImage); return 0; } int main(int argc, char* argv[]) { //int RGB_grafik(frame); //Open the video file for reading VideoCapture cap(0); // if not success, exit the program if (cap.isOpened() == false) { cout << "Cannot open the video file" << endl; cin.get(); //wait for any key press return -1; } /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat hist; //Define the names of windows String windowNameOfOriginalImage = "Original Video"; String windowNameOfHistogramEqualized = "Histogram Equalized Video"; // Create windows with the above names namedWindow(windowNameOfOriginalImage, WINDOW_NORMAL); namedWindow(windowNameOfHistogramEqualized, WINDOW_NORMAL); while (true) {
  • 16. Mat frame; bool bSuccess = cap.read(frame); // Read a new frame from the video file //Breaking the while loop at the end of the video if (bSuccess == false) { cout << "Found the end of the video" << endl; break; } //Convert the frame from BGR to YCrCb color space Mat hist_equalized_image; cvtColor(frame, hist_equalized_image, COLOR_BGR2YCrCb); //Split the image into 3 channels; Y, Cr and Cb channels respectively and store it in a std::vector vector<Mat> vec_channels; split(hist_equalized_image, vec_channels); //Equalize the histogram of the Y channel equalizeHist(vec_channels[0], vec_channels[0]); //Merge 3 channels in the std::vector to form the color image in YCrCB color space. merge(vec_channels, hist_equalized_image); //Convert the histogram equalized image from YCrCb to BGR color space again cvtColor(hist_equalized_image, hist_equalized_image, COLOR_YCrCb2BGR); Mat b_hist, g_hist, r_hist; calcHist(&vec_channels[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&vec_channels[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&vec_channels[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))), Scalar(0, 255, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255), 2, 8, 0); }
  • 17. //show frames in the created windows imshow(windowNameOfOriginalImage, frame); imshow(windowNameOfHistogramEqualized, hist_equalized_image); imshow("calcHist Demo", histImage); RGB_grafik(frame); if (waitKey(5) == 27) { cout << "Esc key is pressed by the user. Stopping the video" << endl; break; } } destroyAllWindows(); //Destroy all opened windows return 0; } Analisa Melihat tujuan dari histogram equalization yang merupakan metode perbaikan kualitas citra untuk meratakan persebaran nilai intensitas piksel suatu citra. Hal ini terlihat pada grafik dari gambar asli dari livecam yang belum mengalami ekualisasi, persebaran nilai piksel RGB nya masih terfokus pada rentang nilai 0 – 128 karena objek yang tertangkap kamera memiliki intensitas cahaya yang cukup serta adanya objek yang berwarna gelap sehingga perpaduan warna RGB nya juga berada pada rentang nilai 0 – 128. Tetapi ketika sudah mengalami ekualifikasi pada gambar, data pembacaan grafik menunjukkan persebarang nilai intensitas piksel yang merata dari rentang 0 – 255 yang berarti bahwa gambar yang telah mengalami ekualifikasi mendapatkan perbaikan kualitas dari citra image sehingga persebaran nilai intensitas piksel pada image tersebut lebih merata. Terutama pada warna biru yang memiliki persebaran merata dari rentang nilai 0 – 255 dibandingkan persebaran warna merah dan hijau yang masih berada pada rentang nilai 128.
  • 18. SEGMENTASI 1. Histogram RGB Image dari Image File #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat frame, gray_frame; frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg". //imshow("RGB Image", frame); /// Separate the image in 3 places ( B, G and R ) vector<Mat> bgr_planes; split(frame, bgr_planes); /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false; Mat b_hist, g_hist, r_hist; /// Compute the histograms: calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms for B, G and R int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw Histogram for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h -
  • 19. cvRound(g_hist.at<float>(i))), Scalar(0, 255, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255), 2, 8, 0); } /// Display imshow("RGB Histogram Image", histImage); imshow("Original Image", frame); waitKey(); return EXIT_SUCCESS; } 2. Hasil gambar intensitas R > 125 #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat frame, gray_frame; frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg". /// Separate the image in 3 places ( B, G and R ) vector<Mat> bgr_planes; split(frame, bgr_planes); /// Establish the number of bins int histSize = 256; /// Set the ranges float range[] = { 125, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false;
  • 20. Mat b_hist, g_hist, r_hist; /// Compute the histograms: calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms for B, G and R int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw Histogram for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255), 2, 8, 0); } /// Display imshow("RGB Histogram Image", histImage); imshow("Original Image", frame); waitKey(); return EXIT_SUCCESS; } Analisa Segmentasi merupakan proses pemisahan latar depan – latar belakang suatu image. Untuk case pada soal ini dimana kami diminta untuk menampilkan grafik dari warna merah yang memiliki nilai intensitas R lebih dari 125, sehingga pada variabel array yang digunakan untuk menampung nilai dari warna diubah dengan nilai pada rentang 126 – 255 yang pada grafik menghasilkan klaster warna merah yang memiliki intensitas pada rentang 126 – 255 dengan kerapatan yang cukup stabil. Hal ini dikarenakan pada pemetaan warna citra dari image masukan dikelompokkan sesuai dengan kesamaan warna yang dimiliki oleh objek pada gambar. Setiap piksel citra dikonversi dalam suatu garis vector RGB untuk selanjutnya ditampilkan berdasarkan rata – rata dari kelompok warna yang dihasilkan.
  • 21. Menampilkan Warna Merah Saja dari Image #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat frame; frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR); /// Separate the image in 3 places ( B, G and R ) vector<Mat> bgr_planes; split(frame, bgr_planes); /* Mat redOnly, mask; Mat hsv_image; cvtColor(frame, hsv_image, COLOR_BGR2HSV); inRange(hsv_image, Scalar(0, 120, 70), Scalar(10, 255, 255), mask); */ Mat g, output; g = Mat::zeros(Size(frame.cols, frame.rows), CV_8UC1); // Showing Red Channel // G and B channels are kept as zero matrix for visual perception vector<Mat> channels; channels.push_back(g); channels.push_back(g); channels.push_back(bgr_planes[2] > 125); /// Merge the three channels merge(channels, output); namedWindow("Red", 1); ///Converting image from BGR to HSV color space. Mat hsv_image; cvtColor(frame, hsv_image, COLOR_BGR2HSV); /// Creating masks to detect the upper and lower red color. Mat mask1, mask2, red_output; inRange(hsv_image, Scalar(0, 40, 30), Scalar(10, 255, 255), mask1); //inRange(hsv_image, Scalar(130, 120, 120), Scalar(180, 255, 255), mask2); // Generating the final mask //mask1 = mask1 + mask2; bitwise_and(frame, frame, red_output, mask1); /// Establish the number of bins int histSize = 256; /// Set the ranges ( for B,G,R) ) float range[] = { 0, 256 }; const float* histRange = { range }; bool uniform = true; bool accumulate = false;
  • 22. Mat b_hist, g_hist, r_hist; /// Compute the histograms: calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate); calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate); // Draw the histograms for B, G and R int hist_w = 512; int hist_h = 400; int bin_w = cvRound((double)hist_w / histSize); Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0)); /// Normalize the result to [ 0, histImage.rows ] normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); /// Draw for each channel for (int i = 1; i < histSize; i++) { line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))), Scalar(0, 255, 0), 2, 8, 0); line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))), Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255), 2, 8, 0); } /// Display namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE); imshow("calcHist Demo", histImage); imshow("Image", frame); imshow("Red", output); imshow("Red Only", red_output); waitKey(); return EXIT_SUCCESS; }
  • 23. Segmentasi pada suatu citra ( image segmentation) merupakan langkah awal pada proses analisa citra yang bertujuan untuk mengambil informasi yang terdapat di dalam suatu citra. Segmentasi citra membagi suatu citra ke dalam bagian-bagian atau objek-objek tertentu. Sampai sejauh mana pembagian tersebut dilakukan tergantung pada masalah yang dihadapi. Idealnya, langkah segmentasi tersebut dihentikan pada saat objek yang diinginkan sudah berhasil dipisahkan. Pada kasus diatas, dari sampul buku terlebih dahulu dipisahkan dengan trasholding untuk mengetahui dan memisahkan warna merah. Setelah warna merah sudah dapat diketahui selanjutnya bagian yang selain warna merah dihitankan atau dihapus.