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 9196449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:51:08+00:00 2026-06-17T21:51:08+00:00

I tried to display an image of CV_32F type using imshow function but it

  • 0

I tried to display an image of CV_32F type using imshow function but it showed a WHITE image. In the Documentation its given that floating point images will be mapped to 0-255 and displayed but it just showed a white image.I tried to convert it to CV_8U using

Mat A=Mat::ones(300,300,CV_32FC1)*1000;

do some processing – assigning float values to pixels in A

……

Mat B;

A.convertTo(B,CV_8U)

When I imshow ‘B’ i get a black & white image, there are no shades of gray. Are the float valued pixels in A properly mapped to 0-255 ? Am I doing anything wrong?

Few values in A are 1000 as initialized and rest are some floating point numbers which are assigned during processing.

  • 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-17T21:51:09+00:00Added an answer on June 17, 2026 at 9:51 pm

    In OpenCV, if the image is of floating point type, then only those pixels can be visualized using imshow, which have value from 0.0 to 1.0, if the value is greater than 1.0, it will be shown as a white pixel and if less than 0.0, it will be shown as black pixel.
    To visualize a floating point image, scale its values to the range 0.0 - 1.0.

    As for the conversion part…. When used with default arguments, the cv::Mat::convertTo function just creates a matrix of the specified type, and then copies the values from the source matrix and then rounds them to the nearest possible value of the destination data type.
    If the value is out of range, it is clamped to the minimum or maximum values.

    In the documentation of imshow, it is written that:

    If the image is 32-bit floating-point, the pixel values are multiplied
    by 255. That is, the value range [0,1] is mapped to [0,255].

    It means that only the values in the range 0.0 to 1.0 will be mapped to 0 to 255. If a value is greater than 1.0, and multiplied by 255, it will become greater than 255. Then it will be clamped to the range of CV_8U and eventually it will also become 255.

    In your example, all the values which are 1000, will become 255 in the destination matrix as the destination type is CV_8U and the maximum possible value is 255. All the floating point values will be floored. No automatic mapping is done.

    To appropriately map the values to the range of CV_8U use the 3rd and 4th parameters of the function cv::Mat::convertTo, so that the values are scaled before the conversion is done.

    Suppose the matrix A has minimum and maximum values Min and Max, where Min!=Max.

    To properly scale the values from 0 to 255, you can do the following:

    if (Min!=Max){ 
        A -= Min;
        A.convertTo(B,CV_8U,255.0/(Max-Min));
    }
    

    You can also do this directly like this:

    if (Min!=Max)
        A.convertTo(B,CV_8U,255.0/(Max-Min),-255.0*Min/(Max-Min));
    

    (edited taking into account zhangxaochen’s comment)

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

Sidebar

Related Questions

I have tried using the code below but it only display results in Chrome
When I tried to to create an image I was using this line but
How can I display an image in a message box. I tried about.setIcon(:/pics/goku3.jpg); but
In android phonegap application I crated canvas using html and display image in that
I tried to display the url using all sorts of methods of HttpRequest, I
Problem occured when i tried to display xml data that has been taken by
This page should display a Google ad. I Tried everything but it's not working.
I'm using Dygraphs to display data. Specifically - Dygraph.Gvizchart. I've tried using connectSeparatedPoint option
i am trying to display an image by using the < img > tag
I tried to display imagecells in tableview, but the program crashes.. here's my imageCell

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.