How to import images to this function? need help

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

 Respuesta aceptada

Image Analyst
Image Analyst el 31 de Mzo. de 2019
You'd do
im = varargin{1};
minRadius = varargin{2}
maxRadius = varargin{3}

11 comentarios

Arshad Ali
Arshad Ali el 31 de Mzo. de 2019
i am new in matlab don,t have any idea how would i do that? can you please tell me more clearly? and how i use this in the above code to import images? Thanks in advance
function sp = LoG(varargin)
% USAGE:
% sp = LoG(<input image>, <minimum radius>, <maximal raidus> , <detection threshold>);
% Get arguments and/or default values
im = varargin{1};
if nargin >= 2
% They've passed something in.
minRadius = varargin{2}
else
% Nothing passed in use default
minRadius = 5;
end
if nargin >= 3
% They've passed something in.
maxRadius = varargin{3}
else
% Nothing passed in use default
maxRadius = 10;
end
if size(im,3) > 1
etc.
Arshad Ali
Arshad Ali el 31 de Mzo. de 2019
hello sir it gives me error likr this
Index exceeds array bounds.
Error in Untitled2 (line 5)
im = varargin{1};
Then nothing is being passed in at all, not even an image. Try this
if nargin == 0
im = varargin{1};
else
im = imread('cameraman.tif') % Create some default.
end
Arshad Ali
Arshad Ali el 31 de Mzo. de 2019
Editada: Arshad Ali el 31 de Mzo. de 2019
agian it gives me the same error
Index exceeds array bounds.
Error in Untitled2 (line 6)
im = varargin{1};
Image Analyst
Image Analyst el 31 de Mzo. de 2019
  1. What is nargin's value?
  2. Attach your .m and .fig file, and
  3. tell me how you're calling sp = LoG(varargin).
Arshad Ali
Arshad Ali el 31 de Mzo. de 2019
any value you can give to varargin.
i am calling function like that.
sp = LoG(5);
Image Analyst
Image Analyst el 31 de Mzo. de 2019
OK, that answered only #3.
Why are you not answering the two others?
Arshad Ali
Arshad Ali el 31 de Mzo. de 2019
actually this code is written by other person. you can check the LoG.m files
Walter Roberson
Walter Roberson el 31 de Mzo. de 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
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Variables en Centro de ayuda y File Exchange.

Preguntada:

el 31 de Mzo. de 2019

Comentada:

el 31 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by