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

  • Home
  • SEARCH
  • 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 7072141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:46:21+00:00 2026-05-28T05:46:21+00:00

I want to get the maximum values from two images, while preserving other information.

  • 0

I want to get the maximum values from two images, while preserving other information.

For example, I have two images in HSL format, and I want the resulting image to consist of the brightest pixels. (this is an example, in reality I can’t convert to RGB, finding max, and converting back)

So I cannot use cvMax because it will separately give me the maximum H, maximum S and maximum L.

What I need is an image with the maximum L from either image, accompanied by the H and S values (or other information) from the same image.

For example, consider these 2×1 pixel images, with their HSV scalars:

IplImage* img1 = cvCreateImage(cvSize(2, 1), IPL_DEPTH_32F, 3);
cvSet2D(img1, 0, 0, cvScalar(1, 2, 45)); // Remember: HSV values
cvSet2D(img1, 0, 1, cvScalar(3, 4, 123));
IplImage* img2 = cvCreateImage(cvSize(2, 1), IPL_DEPTH_32F, 3);
cvSet2D(img1, 0, 0, cvScalar(5, 6, 114));
cvSet2D(img1, 0, 1, cvScalar(7, 8, 33));

IplImage* result = cvCreateImage(cvSize(2, 1), IPL_DEPTH_32F, 3);

//Do something to get the brightest pixels

CvScalar px0 = cvGet2D(result, 0, 0);
CvScalar px1 = cvGet2D(result, 0, 1);

cout << px0.val[0] << " " << px0.val[1] << " " << px0.val[2] << endl;
cout << px1.val[0] << " " << px1.val[1] << " " << px1.val[2] << endl;

Output should become:

5 6 114
3 4 123

Is there a neat ‘OpenCV’ way of doing this, instead of making my own, possibly slower, algorithm that parses each pixel?


Just an idea, but can I do something like this?

  • Split them into 6 grayscale images, (actually, I already have this situation, so I don’t need to split)
  • Take both V images,
  • Generate a per-element map (1U or 8U image) where a ‘0’ or ‘1’ value means the highest value was in the first or second image respectively.
  • Use this to combine selected pixels from the other planes.

The bold step is where I’m stuck.

  • 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-05-28T05:46:21+00:00Added an answer on May 28, 2026 at 5:46 am

    There is no build-in opencv function to do it, but it’s not thah difficult to write your own.

    You can simply

    for(i=0;i<h;i++)
       for (j=0;j<w;j++)
          dst[j+w*i] = (src1[j+w*i]>src2[j+w*i])?src1[]:src2[];
    

    Of course, some little optimization can be done, like precalculating j+w*i, or using pointer access instead of array indexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have an NSFont, and I want to get the maximum dimensions for
I want to get my databases under version control. I'll always want to have
I want to get a files these attributes as integer values.
I want to have a gradient with rainbow colors. I have numeric values, the
I want to find the maximum value from the List objects.The class structure is
I want get the maximum value for this record. Please help me: SELECT rest.field1
I have two columns A and B. I want to select the value of
I have folowing sql query an di want to get previous of max value
I want get the time used for a case so I can create an
I want get all of the Geom objects that are related to a certain

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.