Warning: Colon operands cannot be logical
显示 更早的评论
I am trying to use a code for identifying particles in an image based on triangle thresholding. I have it as a function for a larger program that I use. I get the following error:
>> virusf
> In find_virus (line 10)
In virusf (line 30)
> In find_virus (line 10)
In virusf (line 30)
Warning: Colon operands cannot be logical.
Warning: Colon operands cannot be logical.
ctr =
0×2 empty double matrix
This is the code of the program:
function []=virusf()
global FileInfo
global UserValues TcspcData FileInfo PamMeta
h=guidata(findobj('Tag','Pam'));
Det=UserValues.Detector.Det(h.MI.Phasor_Det.Value);
Rout=UserValues.Detector.Rout(h.MI.Phasor_Det.Value);
From=str2double(h.MI.Phasor_From.String);
To=str2double(h.MI.Phasor_To.String);
PIE_MT=TcspcData.MT{Det,Rout}(TcspcData.MI{Det,Rout}>=From & TcspcData.MI{Det,Rout}<=To)*FileInfo.ClockPeriod;
[Intensity, Bin] = CalculateImage(PIE_MT, 2);
PIE_MI=TcspcData.MI{Det,Rout}(TcspcData.MI{Det,Rout}>=From & TcspcData.MI{Det,Rout}<=To);
PIE_MI=PIE_MI(Bin~=0);
Bin=Bin(Bin~=0);
Pixel= cumsum(Intensity(:));
Intensity=double(reshape(Intensity,[FileInfo.Pixels,FileInfo.Lines]));
Intensity=flip(Intensity',1);
BitImage = (Intensity>str2double(h.MI.Phasor_ParticleTH.String));
im = BitImage;
[ctr]=find_virus(im, 0, 20, 1)
and the find_virus code:
function [ctr]=find_virus(im, add_th, min_area, flg)
%find single virus in a image
%if flg=1, plots the image
%add_th: tune to discard dimmer spots
%min_area: adjust to discard small spots
%-spots bigger than 10x min_area will also be discarded
th=H_thresh_triangle_img2008v1(im,length(min(im(:)):1:max(im(:))),1); %find threshold automatically
th=round(th);
th=th+mean(im(:))*add_th;%add value to adjust th for the type of images (high S/N -> high add_th)
BW=im;
BW(BW(:)<th)=0; BW(BW(:)>th)=1; %create binary image
s=regionprops(logical(BW),'centroid', 'area', 'PixelList'); %get centers and area
ar=cat(1, s.Area);
ctr=cat(1, s.Centroid);
lst = cat(1, s.PixelList);
ctr(ar<min_area | ar>10*min_area,:)=[];%remove center of small points and very big areas
The code is larger but the error is coming from the line 10 where the trhesholding is done
采纳的回答
更多回答(1 个)
Adam
2017-4-13
It is pretty much exactly as the error says.
im is binary therefore min( im(:) ) is also binary. Wrap it up in e.g.
double( min( im(:) ) )
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!