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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:49:14+00:00 2026-05-21T20:49:14+00:00

I am trying to understand this code: d=edge(d,’canny’,.6); figure, imshow(d,[]) ds = bwareaopen(d,40); figure,

  • 0

I am trying to understand this code:

d=edge(d,'canny',.6);
figure,
imshow(d,[])

ds = bwareaopen(d,40);
figure,
imshow(ds,[])

iout = d1;
BW=ds;

iout(:,:,1) = iout;
iout(:,:,2) = iout(:,:,1);
iout(:,:,3) = iout(:,:,1);
iout(:,:,2) = min(iout(:,:,2) + BW, 1.0);
iout(:,:,3) = min(iout(:,:,3) + BW, 1.0);

I understand that d is the image and canny detector is applied and 40 pixels are neglected. The image is gray scale and contour is added to the image.

Can you please explain the next lines? What principle/algorithm is used here? I am having trouble especially with the contour detection portion of the code.

  • 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-21T20:49:15+00:00Added an answer on May 21, 2026 at 8:49 pm

    Assuming that the variable d1 stores what is likely a double precision representation (values between 0 and 1) of the original grayscale intensity image that is operated on, then the last 5 lines will turn that grayscale image into a 3-D RGB image iout that looks the same as the original grayscale image except that the contours will be overlaid on the image in cyan.

    Here’s an example, using the image 'cameraman.tif' that is included with the MATLAB Image Processing Toolbox:

    d1 = double(imread('cameraman.tif'))./255;  % Load the image, scale from 0 to 1
    subplot(2, 2, 1); imshow(d1); title('d1');  % Plot the original image
    d = edge(d1, 'canny', .6);                  % Perform Canny edge detection
    subplot(2, 2, 2); imshow(d); title('d');    % Plot the edges
    ds = bwareaopen(d, 40);                     % Remove small edge objects
    subplot(2, 2, 3); imshow(ds); title('ds');  % Plot the remaining edges
    iout = d1;
    BW = ds;
    iout(:, :, 1) = iout;                           % Initialize red color plane
    iout(:, :, 2) = iout(:, :, 1);                  % Initialize green color plane
    iout(:, :, 3) = iout(:, :, 1);                  % Initialize blue color plane
    iout(:, :, 2) = min(iout(:, :, 2) + BW, 1.0);   % Add edges to green color plane
    iout(:, :, 3) = min(iout(:, :, 3) + BW, 1.0);   % Add edges to blue color plane
    subplot(2, 2, 4); imshow(iout); title('iout');  % Plot the resulting image
    

    And here is the figure the above code creates:

    enter image description here

    How it works…

    The creation of the image iout has nothing to do with the edge detection algorithm. It’s simply an easy way to display the edges found in the previous steps. A 2-D grayscale intensity image can’t display color, so if you want to add colored contour lines to the image you have to first convert it to a format that will let you show color: either an indexed image (which is a little harder to deal with, in my experience) or a 3-D RGB image (the third dimension represents the red, green, and blue color components of each pixel).

    Replicating the grayscale image 3 times in the third dimension gives us a 3-D RGB image that initially still contains gray colors (equal amounts of red, green, and blue per pixel). However, by modifying certain pixels of each color plane we can add color to the image. By adding the logical edge mask BW (ones where edges are and zeroes elsewhere) to the green and blue color planes, those pixels where the contours were found will appear cyan. The call to the function min ensures that the result of adding the images never causes a pixel color value to exceed the value 1.0, which is the maximum value an element should have for a double-precision 3-D RGB image.

    It should also be noted that the code for creating the 3-D RGB image can be simplified to the following:

    iout = d1;
    iout(:, :, 2) = min(d1+ds, 1.0);
    iout(:, :, 3) = min(d1+ds, 1.0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand this simple hashlib code in Python that has been
I'm still trying to understand this piece of code that I found in a
I am trying to understand this inline assembly code which comes from _hypercall0 here
Trying to understand the math of this code snippet. A token is provided which
I grabbed this code form JCarousel and just trying to understand these lines below.
I have got this code and I am trying to understand the convention followed,
Trying to understand Ruby a bit better, I ran into this code surfing the
New programmer here, I am trying to understand and break down this code below
I am trying to understand this code: #include<stdio.h> int main() { extern int a;
I'm trying to understand this code from Deitels 5th edition c book. If I'm

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.