Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:51:09+00:00 2026-06-18T08:51:09+00:00

Sorry if this question is so basic, I’m new with OpenCV. I want to

  • 0

Sorry if this question is so basic, I’m new with OpenCV.

I want to apply histogram equalisation to an RGB image. HE only works for single channel so I figured that I have to split the image into 3 different channels, apply HE to each one of them, then merge them all together to form output equalised image.

So I did just that and here’s my program which I REALLY believe should work:

#include <iostream>
#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char * argv[])
{
IplImage* img = cvLoadImage("/Users/Documents/red.jpg");  //Load image file
cvNamedWindow("Trans-in", CV_WINDOW_AUTOSIZE );     //Create input window
cvNamedWindow("Trans-out", CV_WINDOW_AUTOSIZE  );   //Create output window

cvShowImage("Trans-in", img );  //Show input image in input window

//Create space for outputs rgb and its separate channels, r, g and b
IplImage* img0 = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);    //rgb
IplImage* r = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);    //r
IplImage* g = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);    //g
IplImage* b = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);    //b

//cvZero(r);
//cvZero(g);
//cvZero(b);

cvSplit(img, b, g, r, NULL);       //OpenCV likes it in BGR format

cvEqualizeHist( img, r );    //equalise r
cvEqualizeHist( img, g );    //equalise g
cvEqualizeHist( img, b );    //equalise b


cvMerge(b, g, r, NULL, img0);  //merge all separate channels together to output image rgb

//cvReleaseImage(&r);
//cvReleaseImage(&g);
//cvReleaseImage(&b);

cvShowImage("Trans-out", img0); //Show output image in output window


cvWaitKey(0);
cvReleaseImage( &img);
cvReleaseImage( &img0);

cvDestroyWindow( "Trans-in");
cvDestroyWindow( "Trans-out");

return 0;
}

Apologies if the //comments are a bit annoying, but it shows my ‘reasoning’ I guess. Xcode didn’t complain until I hit the ‘Run’ button. It basically crashed (input image shows, but not output image).

Plus an error message at the bottom:

OpenCV Error: Assertion failed (CV_ARE_SIZES_EQ(src, dst) && CV_ARE_TYPES_EQ(src, dst) && CV_MAT_TYPE(src->type) == CV_8UC1) in cvEqualizeHist, file /opt/local/var/macports/build/_Volumes_work_mports_dports_graphics_opencv/opencv/work/OpenCV-2.4.3/modules/imgproc/src/histogram.cpp, line 2414 terminate called throwing an exception

And I have no idea what it means or what to do next.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:51:11+00:00Added an answer on June 18, 2026 at 8:51 am

    You are using the cvEqualizeHist function incorrectly in the following lines:

    cvEqualizeHist( img, r );    //equalise r
    cvEqualizeHist( img, g );    //equalise g
    cvEqualizeHist( img, b );    //equalise b
    

    img is a 3 channel image while r,g and b are single channel images. cvEqualizeHist doesn’t work on 3 channel images.

    You have to do the following:

    cvEqualizeHist( r, r );    //equalise r
    cvEqualizeHist( g, g );    //equalise g
    cvEqualizeHist( b, b );    //equalise b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to world of matrix, sorry for this basic question I could
Edit Question: Sorry about this basic question. This is a new technology to me.
I'm sorry if this is a basic question(I'm new to c/c++, but I'm a
I'm new to Django, sorry if this is a basic question. I need to
I'm sorry if this question is basic(I'm new to nosql). Basically I have a
Sorry this is a basic question, but all my research just barely missed answering
I'm sorry if this question is a bit basic, or if I've missed an
Sorry if this is a really basic question but it's been really getting to
Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
Sorry, another super basic ASP.NET question. this so embarrassing. I am reading the article

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.