How to import images to this function? need help

1 view (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 31 Mar 2019
You'd do
im = varargin{1};
minRadius = varargin{2}
maxRadius = varargin{3}
  11 Comments
Walter Roberson
Walter Roberson on 31 Mar 2019
You cannot call that code just passing in a single scalar value. You must pass in at least 4 values.
  1. 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
  2. the second must be the minimum radius to use
  3. the third must be the maximum radius to use
  4. the fourth must be the dection threshold
Image Analyst
Image Analyst on 31 Mar 2019
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!