what is the meaning of BW = ~ BW?

조회 수: 34 (최근 30일)
Shaila parvin
Shaila parvin 2013년 5월 28일
function [shape] = Classify(ImageFile)
if ndims(imread(ImageFile))>2
RGB = imread(ImageFile);
GRAY = rgb2gray(RGB);
else
GRAY=imread(ImageFile);
%RGB=GRAY;
end
threshold = graythresh(GRAY);
BW = im2bw(GRAY, threshold);
%Invert the Binary Image
BW = ~ BW;
[~,L] = bwboundaries(BW, 'noholes');
STATS = regionprops(L,'all');
for i=1:length(STATS)
if norm([STATS(i).Extrema(2,1), STATS(i).Extrema(2,2)]-[STATS(i).Extrema(1,1), STATS(i).Extrema(1,2)])<5 %TR,TL
%can be triangle hexagon pentagon
if norm([STATS(i).Extrema(4,1), STATS(i).Extrema(4,2)]-[STATS(i).Extrema(3,1), STATS(i).Extrema(3,2)])<5 %RT,RB
%can be pentagon triangle
if norm([STATS(i).Extrema(4,1), STATS(i).Extrema(4,2)]-[STATS(i).Extrema(5,1), STATS(i).Extrema(5,2)])<5 %RT,RB,BR = Triangle
shape(i,1)=1; % Triangle
else
shape(i,1)=3; % Pentagon
end
else
shape(i,1) = 4; % hexagon
end
elseif (STATS(i).MajorAxisLength/STATS(i).MinorAxisLength<1.1 && STATS(i).Eccentricity <0.5 || (STATS(i).Solidity/STATS(i).Extent)==1)&(STATS(i).Area<0.1*numel(GRAY))
shape(i,1)=2; % Rectangle
else
shape(i,1)=0;
end
end
if ~isempty(find(shape==2))
disp('Rectangle found');
else
disp('No rectangle in the image')
end
return
what is the meaning of
BW = ~ BW;
this line?
  댓글 수: 1
Shaila parvin
Shaila parvin 2013년 5월 28일
what is the meaning of this line?
BW = im2bw(GRAY, threshold);

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 28일
~ is logical negation in this context. If you selected one area into BW, then ~BW is everything else that was not that area. bwthresh selects areas with grey scale above a certain level; ~BW would then be everywhere with grey scale below that level. Useful if you have black letters on a light background for example.

추가 답변 (1개)

John Doe
John Doe 2013년 5월 28일
It gives you back the inverted binary matrix BW. That means, all 1's turns to 0's, and vice versa.
In plain text:
BW = not BW.
Suppose the binary image is represented as:
BW =
1 1 1 1
1 0 1 0
0 0 0 1
1 1 1 0
Then BW = ~ BW gives:
BW =
0 0 0 0
0 1 0 1
1 1 1 0
0 0 0 1
Hope this answers your question =)
- Robert
  댓글 수: 1
Shaila parvin
Shaila parvin 2013년 5월 28일
what is the meaning of this line?
BW = im2bw(GRAY, threshold);

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by