can i call my binary image as contour map, if yes then how can i extract contour outline without using any dialation approach

3 views (last 30 days)
i have two thresholded images. one is thresholded by a single threshold and other is threshoded my multiple threshold. can i call those thresholded (binary) as contour-map. if yes how can i get the coordinates of boundary pixels. i want to get the bourndary but without any dialation operation.

Accepted Answer

Image Analyst
Image Analyst on 27 Dec 2013
I'm not sure what multi-thresholded means to you but if you used imquantize() or something and have a single gray level for each region than you can create a binary image. See this demo:
% Demo to quantize a grayscale image and find boundaries.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
% Create a sample image.
grayImage = uint8(255*mat2gray(peaks(300)));
fh = figure();
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
edges = [50, 100, 150];
quantizedImage = imquantize(grayImage, edges);
% Display the quantized image.
subplot(2, 2, 2);
imshow(quantizedImage, []);
title('Quantized Grayscale Image', 'FontSize', fontSize);
for r = 1 : length(edges)
% Extract the binary image for region #2
binaryImage = quantizedImage == r;
% Display the quantized image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
x = thisBoundary(:,2);
y = thisBoundary(:,1);
plot(x, y, 'r-', 'LineWidth', 4);
end
hold off;
promptMessage = sprintf('Do you want to Continue processing,\nor Cancel to abort processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
end
close(fh);

More Answers (1)

Walter Roberson
Walter Roberson on 27 Dec 2013
bwboundaries(), bwtraceboundary()
  1 Comment
Bilal
Bilal on 27 Dec 2013
this work on binary image, 0 and 1. what about the multi-thresholded image? these functions treat all non-zero items as single object.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!