Change image type : Convert 8U to 32F or 64F

void Mat::convertTo(OutputArray m, int rtype, double alpha=1, double beta=0 )

Parameters:
  • m – output matrix; if it does not have a proper size or type before the operation, it is reallocated.
  • rtype – desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.
  • alpha – optional scale factor.
  • beta – optional delta added to the scaled values.
saturate_cast<> is applied at the end to avoid possible overflows:
m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) +  \beta )

Steps:

  1. Load an image 
  2. Convert image type
  3. Show result

Functions:

Example:

-------------
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"

using namespace cv;
using namespace std;

int main( )
{

    Mat src1;
    src1 = imread("lena.jpg", CV_LOAD_IMAGE_COLOR); 
    namedWindow( "Original image", CV_WINDOW_AUTOSIZE ); 
    imshow( "Original image", src1 ); 
    Mat dst,dst1;
    // Change image type from 8UC1 to 32FC1
    src1.convertTo(dst, CV_32F);

    cout << "src1 intensity = " << (int) src1.at<Vec3b>(2,5)[0] << endl << "dst intensity = " << dst.at<Vec3f>(2,5)[0] <<endl << endl;
    // both intensity are same, but one is 8U and other is 32F

    dst.convertTo(dst1,CV_8U,1.5,10); // converting back to 8U with scaling
    namedWindow( "dst1", CV_WINDOW_AUTOSIZE );  
    imshow( "dst1", dst1 );
    
    waitKey(0);                                         
    return 0;
}
--------------

57 comments:

  1. src1.convertTo(dst, CV_32F);
    namedWindow("dst", CV_WINDOW_AUTOSIZE);
    imshow("dst", dst); Why I get a white screen?

    ReplyDelete
    Replies
    1. Generally we use unsigned 8 bit format to represent image, which is compatible in most of the library functions. When the image is converted to 32 bit, the imshow function is not able to display it properly. Probably, all nonzero values are considered as 1 when the image is in 32bit and the image looks like a white screen.

      Delete
  2. I really enjoy reading of your article. I wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this.
    ivanka trump hot pics

    ReplyDelete
  3. Thanks for sharing this useful post. I'd like to share an awesome useful online tool please check out. https://onlineconvertfree.com/

    ReplyDelete
  4. Excellent erudition Providing by your Article, thank you for taking the time to share with us such a nice article. Amazing insight you have on this, it's nice to find a website that details so much information about different artists. Kindly visit the LiveWebTutors website we providing the best online assignment help services in Australia.

    For More Info: Assignment Help Brisbane

    ReplyDelete
  5. Converting 8U to 32F or 64F was an intimidating task for me and I was restless due to the lack of knowledge about this task but I have fulfilled it after reading your content. Thanks for sharing comprehensible content for your reader. Dissertation Writing Services

    ReplyDelete
  6. Great job... Its really great to know the change of image types and resizing. Best way to convert JPG to DST and other formats. Thanks a lot.

    ReplyDelete
  7. If it wasn't for the help provided by BookMyEssay I would not have been able to achieve the excellent grades I had. I thought you may also need the same to make things easy for you. If you wish to get the help you may go to their website through the page Dissertation Writing Help Service . It was really a pleasant experience talking to them. They did all my work at a very reasonable cost and helped me to submit everything before deadline.

    ReplyDelete
  8. Procurement Resource does an in-depth analysis of the market trend to bring forth the monthly, quarterly, half-yearly, and yearly information on the BR (Butadiene Rubber) Prices, Butter Prices and Butter Oil Prices in its latest pricing dashboard. The detailed assessment deeply explores the facts about the product, price change over the weeks, months, and years, key players, industrial uses, and drivers propelling the market and price trends.

    Also Visit my Blog - https://procurementresource.blogspot.com/

    ReplyDelete
  9. Strong investment in the healthcare market is driving demand for 3D food printing. 3D food printers create foods rich in specific nutrients that are simpler to chew and swallow for the elderly, making it convenient to eat for patients. The growing awareness among food innovators of the need to update food processing technologies is one factor that is driving the demand for 3D food printing. The rising food sector, the demand for customised nutrient-based food products, and worldwide food safety and development concerns are all driving the 3D food printing market forward.

    ReplyDelete
  10. Thank you for sharing the blog. This blog is very useful and informative to everyone. We discovered a source of information in this blog; please continue to share content like this.That information you provided is very good and useful.

    SPSS Assignment Help

    ReplyDelete
  11. Perico Ripico Tours: Where adventure meets tranquility! Embark on an unforgettable journey with Perico Ripico Tours, your gateway to breathtaking destinations and extraordinary experiences. From vibrant rainforests to pristine beaches, their expert guides will lead you through hidden gems, allowing you to immerse yourself in the wonders of nature. With Perico Ripico Tours, every moment is a discovery, and every memory is etched with awe.


    Excursion dominican republic Punta Cana

    ReplyDelete
  12. cravings to website building, we understand it all.
    We recognize that the hard part of a brand lies in creating content, and we're here to understand and help many brands to create engaging posts, stories, graphic designing artworks, amazing pitch decks, explainer videos, and many more digital services like SEO, SMM, Logo Design, professional photography, etc.
    https://howshorts.com/

    ReplyDelete
  13. Experiencing trouble with your LaView camera not connecting to WiFi? Don't worry; it's a common issue that can often be resolved with simple troubleshooting steps. For further assistance, visit our website or connect with our technical experts through live chat for personalized support.




    ReplyDelete
  14. For seamless connectivity, visit the extender linksys com login page. Optimize your networking experience with ease. For further assistance, explore our site or consult our technical experts via live chat. Simple solutions await.




    ReplyDelete

  15. Access support and assistance for Arlo devices by logging in at Arlo Com Login. Explore helpful resources, troubleshooting guides, and updates to optimize your Arlo experience. Our user-friendly platform ensures seamless management and enhancement of your Arlo devices.

    ReplyDelete
  16. For seamless printer setup, visit https //ij.start.canon. Simplify your Canon printer installation with our user-friendly guide. Need more assistance? Visit our site or connect with our technical experts via live chat for help.




    ReplyDelete

  17. Gain support and assistance for your Arlo devices by logging in at my arlo com login. Access resources, troubleshooting guides, and updates to optimize your Arlo experience. Our user-friendly platform ensures seamless management and enhancement of your Arlo devices.

    ReplyDelete
  18. Blinkforhome Setup is a breeze, ensuring your home's security is up and running in no time. For additional support, visit our website or connect with our technical experts via live chat for personalized assistance.

    ReplyDelete
  19. We provide assistance for my wifi ext login, offering expert support for a seamless setup and optimization of your WiFi extender. Our team is committed to ensuring reliable connectivity, enhancing your online experience. Connect with us for personalized assistance.





    ReplyDelete
  20. We offer assistance for Arlo login, ensuring a seamless experience. Count on our support for effective guidance. Connect with us to enhance your Arlo device setup and optimize its performance for secure and efficient home monitoring.

    ReplyDelete
  21. "Inspiring read! Your unique take is refreshing and motivating. This post has sparked new ideas and given me the drive to pursue them. Thank you!"

    ReplyDelete
  22. "This post is a testament to the positive impact of gratitude. Thank you for sharing your thoughts."

    ReplyDelete
  23. "Thank you for this inspiring message of gratitude. It’s a wonderful reminder to count our blessings."

    ReplyDelete
  24. Wonderful post! The way you present information is both engaging and educational. Thank you for sharing your expertise with us!

    ReplyDelete
  25. Wonderful post! Your clear and concise writing style makes complex topics easily understandable. Looking forward to more of your work!

    ReplyDelete
  26. I've always struggled with morning workouts, but after reading this, I’m inspired to give it another try. The energy boost alone sounds worth it!
    lowes.com/survey

    ReplyDelete
  27. Your blog is always my go-to for reliable information. Thanks for another fantastic post. Keep up the excellent work!

    ReplyDelete
  28. "Thank you for this excellent post. The insights you provided are both timely and relevant."

    ReplyDelete
  29. "I want to thank you for such a thorough and insightful post. The practical examples you provided were particularly helpful in understanding the topic better."

    ReplyDelete
  30. Great insights! Your post really clarified things for me. Thanks for sharing such valuable information with the community!

    ReplyDelete

  31. "Thank you for providing such valuable information in this post. The level of detail and the clarity with which you explain things is much appreciated."

    ReplyDelete
  32. Thank you for this thorough and informative post. The knowledge you shared is highly appreciated, and I look forward to more content like this.

    ReplyDelete
  33. "Your ability to simplify complex ideas is impressive. Thank you for such a well-crafted post."

    ReplyDelete
  34. "Thank you for addressing this topic in such a thoughtful way. I found it very useful."

    ReplyDelete
  35. Your thoughtful comment is much appreciated; thank you for contributing.

    ReplyDelete
  36. Your thoughtful and well-researched post is much appreciated. Thanks for sharing! https://wwwhomedepotcomsurvey.com/

    ReplyDelete
  37. "I appreciate the care you took in covering every angle of this topic. Thanks for your hard work!"

    ReplyDelete
  38. Thank you for taking the time to write this comprehensive and well-researched article. It’s much appreciated! iforgot.apple.com

    ReplyDelete
  39. "This post addresses key points that are often overlooked. I appreciate your thorough approach to the topic."

    ReplyDelete
  40. Your clear explanations and insights are much appreciated. Thank you!

    ReplyDelete
  41. Your expertise in this area is evident—thank you for sharing it with us! https://www-pchcomactnow.com/

    ReplyDelete
  42. Through its web-based stage, clients can investigate an immense index of items, place orders for conveyance or pickup, and access important assets and advisers for upgrade their home improvement projects.

    ReplyDelete
  43. “Thank you for providing such a comprehensive analysis. This post has been incredibly valuable in enhancing my understanding.”

    ReplyDelete
  44. This is exactly what I needed today! Your writing has such clarity. Thank you for making learning so accessible.

    ReplyDelete

  45. I appreciate how well you explained everything in this post. Thank you!

    ReplyDelete
  46. Thank you for offering such a fresh perspective on this topic.

    ReplyDelete
  47. This article is exactly what I was looking for. You’ve managed to provide clear advice that I can put into action right away.

    ReplyDelete

  48. "Thank you for this brilliant post! It’s always a delight to read your work. Also, for McDonald's customers, the mcdvoice.com survey is a great way to share your opinion."

    ReplyDelete
  49. Thank you for this insightful blog! It’s great to come across valuable content like this. I also wanted to mention that participating in the McDVoice.com survey is a great way to share feedback and improve customer experiences.

    ReplyDelete
  50. Thanks for writing this blog! It reminds me of how companies like McDonald's collect customer feedback through tools like the McDVoice.com survey to improve their services.

    ReplyDelete
  51. This was a pleasure to read! Thank you for taking the time to create such valuable content. rice purity test

    ReplyDelete
  52. Thanks for sharing this amazing blog! Your insights are incredibly helpful. By the way, for anyone interested in enhancing their dining experience, don’t forget to participate in the McDVoice.com survey to provide feedback and get rewards!

    ReplyDelete

  53. This was very informative, thank you! I’ve also been exploring portal.office.com for related tools and tips.

    ReplyDelete
  54. Fantastic post! Thanks for the tips and insights. If you’re ready to dive into Disney+, check out disneyplus.com/begin.

    ReplyDelete
  55. Thanks for sharing this! It’s always a pleasure to read content like this. I also came across some helpful resources on portalofficecom recently—worth checking out!

    ReplyDelete