How to display all the bounding boxes in the image?

6 次查看(过去 30 天)
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

回答(1 个)

KSSV
KSSV 2019-2-7
There is no variable named:
blobMeasurements
I think this variable is
Iprops
in your case......repalce the variable blobMeasurements with Iprops.
  1 个评论
ezhil K
ezhil K 2019-2-7
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by