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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:22:56+00:00 2026-05-25T14:22:56+00:00

I have a problem while implementing the marker controlled watershed in Matlab. The input

  • 0

I have a problem while implementing the marker controlled watershed in Matlab.

The input image is a binary mask which have two clustered object.
An other image is an other binary image where the white regions indicate the markers.

image
marker

Then I try to use the marker controlled watershed to splitting the clustered object. The code is as follows:

bw=imread('Im.jpg'); % read image
bwMarker=imread('Marker.jpg');% read marker
bw(bwMarker)=0; % impose the marker on the image
L=watershed(bw);% do the watershed
%% plot
rgb = label2rgb(L,'jet',[.5 .5 .5]);
figure(2), imshow(rgb,'InitialMagnification','fit')
title('Marker Controlled Watershed transform ')

The result is show as this plot.

enter image description here
It splits the object into two, but the shape is not intact. I want to get the whole object but just a line splitting the two (as shown below) Can anybody help me out? Thanks.

enter image description here

Appended question:
Thank you for yoda provides the answer. However, in this case, the distance transform using ‘cityblock’ is good but if we using ‘euclidean’ it will lead to over segmentation. Because the watershed will depend on the local minimums in the image and it is coincident that the ‘cityblock ‘ distance transform result in correct number of local minimums. If we apply the ‘cityblock’ for other image, it will lead to over segmentation as well.
Now let’s see yoda’s code:

img=im2bw(imread('https://i.stack.imgur.com/qrYCL.jpg'));

imgDist=-bwdist(~img,'cityblock');
imgDist(~img)=-inf; 

% check local minimums
BW = imregionalmin(imgDist);
figure(1), imshow(BW);  
title('Regional Minima in Original Image');

imgLabel=watershed(imgDist); 

The local minimums and the result are shown as follows:

enter image description hereenter image description here

Note that in the left figure, the local minimum are show as white regions. It is observed that only two local minimum shown in the clustered objects. So leads to the good results.

Now let’s take a look at the distance transform by using ‘euclidean’.

imgDist=-bwdist(~img);
imgDist(~img)=-inf; 

% check local minimums    
BW = imregionalmin(imgDist);
figure(1), imshow(BW);  
title('Regional Minima in Original Image');

imgLabel=watershed(imgDist);    

imshow(imgLabel==0,'InitialMagnification','fit')

The local minimums and the result are shown as follows:

enter image description hereenter image description here

Note that in the left figure, the local minimum are show as white regions. It is observed that there are many local minimum shown in the clustered objects region. So this leads to the over-segmented results.

The over segmentation is because the watershed will first check out the local minimums in the image, then base on the local minimums, perform the watershed. Note that if there are too many local minimums than the desired segmented objects, it will lead to over segmentation. The marker controlled watershed is proposed to replace the original local minimums and achieve better result(since each marker will represent one desired segmented object). But I don’t know how to impose the ‘marker’ so that the original local minimums are depressed and the image only have the local minimums specified by the ‘marker’. Thanks.

  • 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-25T14:22:57+00:00Added an answer on May 25, 2026 at 2:22 pm

    Solution 2: Using marker based watershed:

    You can use the function imimposemin to force the local minima to be where your markers are. You’ll need to slighty modify the code in solution 1 below by replacing the first imDist... line with

    imgDist=-bwdist(~img);
    imgDist=imimposemin(imgDist,marker);
    

    The rest of the code is the same. You should get the segmentation as follows:

    enter image description here


    Solution 1: Using Manhattan distance:

    Here is a solution in MATLAB that separates your two clusters:

    img=im2bw(imread('https://i.stack.imgur.com/qrYCL.jpg'));
    
    imgDist=-bwdist(~img,'cityblock');
    imgDist(~img)=-inf;    
    imgLabel=watershed(imgDist);    
    
    imshow(imgLabel==0,'InitialMagnification','fit')
    

    enter image description here

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

Sidebar

Related Questions

I have met an interesting problem while implementing the Observer pattern with C++ and
I have a problem with implementing a new design. While the anchor elements are
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while pasting my contents (or text) generated by Java code
I have a problem while executing a SSIS script component. To be honest I
I have a problem while scrolling images on tableview. I am getting a Signal
I have come across an annoying problem while writing some PHP4 code. I renamed
I have a flash file menu i am having problem while link it to
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby

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.