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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:59:14+00:00 2026-05-26T14:59:14+00:00

I cannot successfully calculate the distance transformation using OpenCV (2.3) on an ubuntu. The

  • 0

I cannot successfully calculate the distance transformation using OpenCV (2.3) on an ubuntu. The output is either black or a copy of the orignial image, but never as expected an greyscale image with gradients.

My code:

Mat input(Size(100,100), CV_8UC1);
circle(input, Point(50,50), 10 Scalar(255,255,255), 15, 0, 0));

Mat output(Size(100,100), CV_32FC1);
distanceTransformation(input, output, CV_DIST_L2, CV_DIST_MASK_3); //Output is completely black
//distanceTransformation(input, output, CV_DIST_L2, CV_DIST_MASK_PRECISE); //Output is a "copy" of input


imshow("in", input);
imshow("out", output);

Any suggestions?

  • 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-26T14:59:15+00:00Added an answer on May 26, 2026 at 2:59 pm

    The first call is correct, but being a distance, it’s not stored as uchar. When you want to display it, OpenCV converts those float (i think) into uchars. And the result seems black.

    Find the max value in the output, and then scale it to fit a grayscale image

    double maxVal = findMaxDistanceSomehow(); 
    
    output.convertTo( displayBuffer, CV_8UC1, 255./maxVal,0);
    
    imshow("dist", displayBuffer);
    

    EDIT

    The first idea was correct, but you actually did not try to find maxVal! You said that by looking at the picture, instead of actually extracting it. Difference between win and fail.

    So, calculate the dist transform using the precise algoritm, and then

    output.convertTo( displayBuffer, CV_8UC1, 10 ,0);
    

    Edit 2

    And you must put the setTo(0) there.

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

Sidebar

Related Questions

I have successfully implemented Autocomplete field from database using sfWidgetFormJQueryAutocompleter but i cannot a
I cannot create working copy from command line using svn utility if resulting full
I've successfully added Customer Attributes that appear correctly in the backend. But I cannot
The file is being created successfully, but I cannot get PrintWriter to print anything
I am using devise successfully, but decided to add the :lockable module. Our table
Symptom: Some users cannot successfully POST, most can successfully POST. When the error occurs,
If an iOS device cannot successfully [NSObject alloc] (because it is out of memory),
I successfully created the Database and inserted a row however I cannot Query it
I (successfully) deployed some sharepoint2010 - Webparts using msbuild. Everything works fine until I
I have successfully created an app to login user and post the tweet using

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.