Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

bwtraceboundary

Posted on 2009-04-19
4
Medium Priority
?
2,004 Views
Last Modified: 2013-11-25
Hello,

Can someone explain me what the following code does ?

Thanks in advance !
BW = imread('blobs.png');
      imshow(BW,[]);
      s=size(BW);
      for row = 2:55:s(1)
        for col=1:s(2)
          if BW(row,col), 
            break;
          end
        end
 
     contour = bwtraceboundary(BW, [row, col], 'W');

Open in new window

0
Comment
Question by:unknown_
  • 2
4 Comments
 
LVL 15

Expert Comment

by:yuk99
ID: 24182082
This code is extract from Matlab's help of bwtraceboundary function.
http://www.mathworks.com/access/helpdesk/help/toolbox/images/bwtraceboundary.html
You show here only part of the code. The full code is below. What the code does is there as well:

Read in and display a binary image. Starting from the top left, project a beam across the image searching for the first nonzero pixel. Use the location of that pixel as the starting point for the boundary tracing. Including the starting point, extract 50 pixels of the boundary and overlay them on the image. Mark the starting points with a green x. Mark beams that missed their targets with a red x.

Do you need line-by-line description? Which lines you don't understand exactly?
BW = imread('blobs.png');
imshow(BW,[]);
s=size(BW);
for row = 2:55:s(1)
   for col=1:s(2)
      if BW(row,col),
         break;
      end
   end
 
   contour = bwtraceboundary(BW, [row, col], 'W', 8, 50,...
                                   'counterclockwise');
   if(~isempty(contour))
      hold on;
      plot(contour(:,2),contour(:,1),'g','LineWidth',2);
      hold on;
      plot(col, row,'gx','LineWidth',2);
   else
      hold on; plot(col, row,'rx','LineWidth',2);
   end
end

Open in new window

0
 
LVL 9

Expert Comment

by:masheik
ID: 24184379
0
 

Author Comment

by:unknown_
ID: 24201189
can someone explain what's the purpose of that for loop in the code ?

for row = 2:55:s(1)
   for col=1:s(2)
      if BW(row,col),
         break;
      end
   end
0
 
LVL 15

Accepted Solution

by:
yuk99 earned 1500 total points
ID: 24201491
The first FOR loop goes through rows starting at row 2, then 2+55=57 row, 112, etc.
The second FOR loop scans all pixels in the selected row and stops at the first one, which is not 0 (not black).
Then it doing bwtraceboundary starting at selecting point (with coordinates row and col), initial direction West, 8-connected neighborhood connectivity, up to 50 boundary pixels, search in counterclockwise direction.
If it finds something the script then plots initial point and the contour in green, if not - the initial point in red.
That's all.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question