Warning: Colon operands cannot be logical
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
guillermo Solís Fernández
am 13 Apr. 2017
Bearbeitet: Stephen23
am 13 Apr. 2017
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
0 Kommentare
Akzeptierte Antwort
Stephen23
am 13 Apr. 2017
Bearbeitet: Stephen23
am 13 Apr. 2017
If im is logical (which it could be if it is a binary image), then line ten contains this:
min(im(:)):1:max(im(:))
whereof course min and max will then also return logical values, which cannot be used with the colon operator (exactly as the error message tells you).
One workaround is to simply convert to double using +:
+min(im(:)):1:+max(im(:))
I have no idea if this makes sense for your algorithm though: you will have to check that yourself.
0 Kommentare
Weitere Antworten (1)
Adam
am 13 Apr. 2017
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(:) ) )
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!