How to import images to this function? need help
조회 수: 1 (최근 30일)
이전 댓글 표시
function sp = LoG(varargin)
% USAGE:
% sp = LoG(<input image>, <minimum radius>, <maximal raidus> , <detection threshold>);
% Get arguments and/or default values
[im, Rmin, Rmax, peakthr] = checkargs(varargin(:));
if size(im,3) >1
img = rgb2gray(im);
else
img = im;
end
img = double(img);
block = [];
for s = Rmin:Rmax
h = -(s^2) * fspecial('log',s*5,s); % minus just so max is what we want
result = imfilter(img,h,'replicate');
% creates a scale space block to find location and scale of nuclei
block = cat(3,block, result);
end
[Cxy, indx] = max(block,[],3);
G = fspecial('gaussian', 20, 2);
Cxy_g = imfilter(Cxy, G,'symmetric');
ir_max = imregionalmax(Cxy_g);
ir_max = ir_max.*Cxy_g;
ir_med = imdilate(ir_max,strel('disk',min(Rmax,6),0));
ir_max = (ir_med == ir_max).*ir_max;
[r, c] = find(ir_max>peakthr);
sp = struct('radius',[],'x',[],'y',[],'px',[],'py',[],'resp',0);
for p = 1:length(r)
sp(p).x = c(p);
sp(p).y = r(p);
sp(p).radius = indx(r(p),c(p)) + Rmin - 1;
sp(p).resp = Cxy(r(p),c(p));
end
댓글 수: 0
채택된 답변
Image Analyst
2019년 3월 31일
You'd do
im = varargin{1};
minRadius = varargin{2}
maxRadius = varargin{3}
댓글 수: 11
Walter Roberson
2019년 3월 31일
You cannot call that code just passing in a single scalar value. You must pass in at least 4 values.
- The first must be an image array -- not the name of an image, but the content of the image, such as the result of imread() of an image
- the second must be the minimum radius to use
- the third must be the maximum radius to use
- the fourth must be the dection threshold
Image Analyst
2019년 3월 31일
The code I gave you (and attach here) does work if you put it in, and call the functions with the variables in the right order: image, minRadius, maRadius.
You can't just pass in 5, which is one of the radii, without passing in things that come before it also. For example if you pass in the min radius, you must pass in the image. So here are the ways you can call it
sp = LoG(grayImage) % Pass in image but no radii
sp = LoG(grayImage, 5) % Pass in image and min radius, but no max radius
sp = LoG(grayImage, 5, 10) % Pass in everything you can, in proper order.
but you cannot do this:
sp = LoG(5) % Pass in either min or max radius with no image first.
as you did.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!