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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:44:03+00:00 2026-06-06T03:44:03+00:00

I have the following code to convert the type of the matrix using cv::Mat.convertTo()

  • 0

I have the following code to convert the “type” of the matrix using cv::Mat.convertTo() function in OpenCV API.

But when I show it using an imshow(), the images are completely different.

The converted image is completely grey.

However, the values in those images(cv::Mat) are the same.

I think I’m missing something very trivial here.

Mat x = imread("/home/jason/Desktop/1.png",0);
Mat y = Mat(x.rows,x.cols,CV_16S,Scalar(0));

x.convertTo(y,CV_16SC1, 1,0);

imshow("x",x);
imshow("y",y);
waitKey(0);

cout<<x.type()<<endl;
cout<<y.type()<<endl;

//verifying the values in the image.

cout<<"rows 10"<<x.row(10)<<endl;
cout<<"rows 10"<<y.row(10)<<endl;
  • 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-06T03:44:05+00:00Added an answer on June 6, 2026 at 3:44 am

    When you are passing CV_16S image to the imshow (or its C equivalent) the pixel values are implicitly recalculated before the visualization by the formula vdisplayed = 128 + vimage/256

    So you probably need to multiply the image by some constant (256?) or convert it to CV_8U before the imshow call.

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

Sidebar

Related Questions

I have the following JavaScript code which I like to convert to jQuery but
I have the following code that is meant to convert milliseconds into hours, mins
I have the following code sample: float val = 16777216.0F; var badResult = Convert.ToDecimal(val);
I have the following FORTRAN code which I need to convert to C or
i have following code to show div on page <div id=all_users> <div id=user11 userid=11
How to convert Varchar to Int in sql server 2008. i have following code
I have following Delphi code: type RegbusReq2=packed record Funct:char; Device:char; Device1:char; Starting:integer; Quantity:smallint; _CRC:Word;
I am trying to convert the following code into python: Columns(C:C).Select Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual
I have the following code $getchats = $api->call(getLatestChats); echo '<pre>'; print_r(array_values($getchats)); echo '</pre>'; which
I have to following code in VS2008 .net 3.5 using WinForms: byte percent =

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.