Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
#include <opencv2opencv.hpp>
#include <opencv2corecore.hpp>
#include <opencv2highguihighgui.hpp>
using namespace cv;
using namespace std;
int main(int argc, char *argv[]) {
if (argc != 2) {
cout << "Usage: display_Image ImageToLoadandDisplay" << endl;
return -1;
}
Mat image;
Mat gray;
image = imread(argv[1], IMREAD_COLOR); //read the files
if (!image.data) //check for invalid input
{
cout << "Could not open or find the image" << endl;
return -1;
}
int h = image.rows;
int w = image.cols;
Mat gr(h, w, CV_8UC1, Scalar(0));
for (int i = 0;i < h;i++) {
for (int j = 0;j < w;j++) {
gr.at<uchar>(i, j) = uchar(0.114*image.at<Vec3b>(i, j)[0]) + uchar(0.587*image.at<Vec3b>(i, j)[1]) + uchar(0.299*image.at<Vec3b>(i, j)[2]);
}
}
cvtColor(image, gray, CV_BGR2GRAY);
// ******************* READ the Pixel intensity *********************
// single channel grey scale image (type 8UC1) and pixel coordinates x=5 and y=2
// by convention, {row number = y} and {column number = x}
// intensity.val[0] contains a value from 0 to 255
int his1[256];
double prob[256];
double cprob[256];
for (int i = 0; i < 256; i++) {
his1[i] = 0;
prob[i] = 0.0;
}
int val = 0;
for (int i = 0;i < h; i++) {
for (int j = 0;j < w; j++) {
val = gr.at<uchar>(i, j); //assigning the pixel value to val
his1[val] = his1[val] + 1; //increasing the value of bin by 1
}
}
for (int i = 0; i < 256; i++) {
prob[i] = (double)his1[i] / (h*w);
if(i==0)
{
cprob[0] = prob[0];
}
else
{
cprob[i] = cprob[i-1] + prob[i];
}
cout << "cprob" << i << ": " << cprob[i] << std::endl;
}
//int max = 0;
//for (int i = 0; i < 256; i++) {
// cout << "Bin" << i << ": " << his1[i] << std::endl;
// if (max < his1[i])
// max = his1[i];
//}
//cout << max;
//Mat him(301, 260, CV_8UC1, Scalar(255));
//int hist[256]; // integer array
//double maxd = max;
//for (int i = 0;i < 255; i++) {
// hist[i] = cvRound(double(his1[i] / maxd) * 300); //calculating histogram bin value
// Point pt1 = Point(i, 300 - hist[i]);
// Point pt2 = Point(i, 300);
// line(him, pt1, pt2, Scalar(0), 1, 8, 0); //scalar 0 = black colour, we are drawing in black colour
//}
namedWindow("Display window", WINDOW_AUTOSIZE);//Create window for
imshow("Display window", gr); //show out the image inside it
//namedWindow("Display window1", WINDOW_AUTOSIZE);
//imshow("Display window1", him); //wait for the user to press a key in the GUI window
cvWaitKey(0);
image.release(); //free memory
gray.release(); //free memory
gr.release();
//him.release();
return 0;
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team