How to display all the bounding boxes in the image?

8 views (last 30 days)
I am trying to segment all the characters using bounding boxes.I have drawn bounding boxes seperately.Now I need to display all the boxes seperately.I have written a cose,But,I get some error in it.How should I rectify it?
Error:
Undefined variable "blobMeasurements" or class "blobMeasurements".
Error in tes (line 63)
thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
% clear all, close all, clc
%%read the image from the location
image = imread('test3.png');
%% show the input image
figure(1)
imshow(image);
title('Input Image');
%% convert the rgb image to gray scale image
if size(image, 3) == 3
image = rgb2gray(image);
end;
%% show the gray scale image
% figure(2)
% imshow(image);
% title('Gray scale image');
%% conver to binary image
image=im2bw(image);
%% show the binary image
% figure(3)
% imshow(image);
% title('Binary image');
%% remove the noise of the image ( remove less than 15px from the binary image)
image = bwareaopen(image,30);
figure,imshow(image);
%% show the noise removed image
% figure(4)
% imshow(image);
% title('noise removed image');
%% edge detection of the image
imageEdge = edge(image);
imshow(imageEdge);
%COUNT LETTER IN TEXT
[Ilabel num]=bwlabel(imageEdge);
disp(num)
%CALCULATE REGION PROPERTIES
Iprops=regionprops(Ilabel);
%SET BOX PROPERTIES INTO VARIABLE
Ibox=[Iprops.BoundingBox];
%RESHAPE 1-D ARRAY
Ibox=reshape(Ibox,[4 num]);
%DRAW BOUNDING BOXES FOR EACH LETTER
for cnt=1:num
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end
hold off
figure;
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
for k = 1 : num % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
% Extract out this coin into it's own image.
subImage = imcrop(originalImage, thisBlobsBoundingBox);
end

Answers (1)

KSSV
KSSV on 7 Feb 2019
There is no variable named:
blobMeasurements
I think this variable is
Iprops
in your case......repalce the variable blobMeasurements with Iprops.
  1 Comment
ezhil K
ezhil K on 7 Feb 2019
Yeah.I have replaced it.But,I don't get the output as seperating all the boxes.What should I do to display all the boxes seperately.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!