Clear Filters
Clear Filters

my output value is double not logical

2 views (last 30 days)
clear all;
clc;
img = imread('green2.jpg');
img_gray = rgb2gray(img);
level = graythresh(img);
img_bw = im2bw(img_gray,level);
imshow(img_bw);
[L2,num2]=bwlabel(img_bw,8); %連通區域標記
B2=false(size(L2));
for i=1:num2
[r,c] = find(L2==i);
left = min(c);
right = max(c);
up = min(r);
down = max(r);
d = (down-up) / (right-left);
if d > 0.8 & d < 1
% [x,y]=find(L2==i); % Done above already
B2 = B2 + bwselect(img_bw, c, r, 8); %%%把滿足長寬比在0.8到2的區域留下
end
end
figure,imshow(B2);
why my B2 set logical but output is double value?

Accepted Answer

KSSV
KSSV on 27 Oct 2017
Edited: KSSV on 27 Oct 2017
A = logical(round(rand(2))) ; % a logical class
B = rand(2) ; % a double class
C = A+B ; % operation between logical and double gives double
So in your case B2 is logical and the output from bwselect(img_bw, c, r, 8) is double....so the result is double.
Have a look on logical and double if you want any conversions.

More Answers (0)

Categories

Find more on Image Processing Toolbox 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!