Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Hi All,

I am working on a project and need to extract corners from the IRIS image. I am not very experienced in MATLAB so found a related code on internet but that is not working properly. Can anyone help me getting this code correct? Please point out the different errors in it. I will be grateful. The error is:

Subscripted assignment dimension mismatch. Error in harrislaplace (line 48)
      harris_pts(l,c) = [l,c,repmat(i,[n,1])];


C#
function points = harrislaplace(img)
    
    img         = double(img(:,:,1));
    img_height  = size(img,1);
    img_width   = size(img,2);

    % SCALE PARAMETERS
    sigma_begin = 1.5;
    sigma_step  = 1.2;
    sigma_nb    = 13;
    sigma_array = (sigma_step.^(0:sigma_nb-1))*sigma_begin;


    % PART 1 : HARRIS
    harris_pts = zeros(img_height,img_width);
    for i=1:sigma_nb

        % scale (standard deviation)
        s_I = sigma_array(i);   % intégration scale
        s_D = 0.7*s_I;          % derivative scale %0.7

        [Ix, Iy] = imgradientxy(img);
         
        
        % auto-correlation matrix
        g   = fspecial('gaussian',max(1,fix(6*s_I+1)), s_I);
        
        Ix2 = conv2(Ix.^2, g,  'same');
        Iy2 = conv2(Iy.^2, g,  'same');
        Ixy = conv2(Ix.*Iy, g, 'same');

        % interest point response
      
        k = 0.04; 
        cim = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2;	% Original Harris measure.

        % find local maxima on neighborgood
        [l,c,max_local] = findLocalMaximum(cim,3*s_I);%3*s_I

        % set threshold 1% of the maximum value
        t = 0.2*max(max_local(:));

        % find local maxima greater than threshold
        [l,c] = find(max_local>=t);

        % build interest points
        n = size(l,1);
        harris_pts(l,c) = [l,c,repmat(i,[n,1])];
    end


    % PART 2 : LAPLACE
    
    % compute scale-normalized laplacian operator
    laplace_snlo = zeros(img_height,img_width,sigma_nb); % sigma_nb matrices of size img_height by img_width
    for i=1:sigma_nb
        s_L = sigma_array(i);   % scale
        laplace_snlo(:,:,i) = s_L*s_L*imfilter(img,fspecial('log', floor(6*s_L+1), s_L),'replicate');
    end
    % verify for each of the initial points whether the LoG attains a maximum at the scale of the point
    n   = size(harris_pts,1);
    cpt = 0;
    points = zeros(n,3);
    for i=1:n
        l = harris_pts(i,1);
        c = harris_pts(i,2);
        s = harris_pts(i,3);
        val = laplace_snlo(l,c,s);
        if s>1 && s<sigma_nb
            if val>laplace_snlo(l,c,s-1) && val>laplace_snlo(l,c,s+1)
                cpt = cpt+1;
                points(cpt,:) = harris_pts(i,:);
            end
        elseif s==1
            if val>laplace_snlo(l,c,2)
                cpt = cpt+1;
                points(cpt,:) = harris_pts(i,:);
            end
        elseif s==sigma_nb
            if val>laplace_snlo(l,c,s-1)
                cpt = cpt+1;
                points(cpt,:) = harris_pts(i,:);
            end
        end
    end
    points(cpt+1:end,:) = [];
    
    % SET SCALE TO 3*SIGMA FOR DISPLAY
    points(:,3) = 3*sigma_array(points(:,3));
end


What I have tried:

I tried checking output of each executed lines. Size of l and c is very small as compared to the entire image which is not supposed to be because both l and c shows the x, y positions of the corner pixel in the image. One function is called by above code which finds local maxima is mentioned below:

function [row,col,max_local] = findLocalMaximum(val,radius)
% FIND UNIQUE LOCAL MAXIMA USING FILTERING (FAST)
mask = fspecial('disk',radius)>0;
nb = sum(mask(:));
highest = ordfilt2(val, nb, mask);
second_highest = ordfilt2(val, nb-1, mask);
index = highest==val & highest~=second_highest;
max_local = zeros(size(val));
max_local(index) = val(index);
[row,col] = find(index==1);
end
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900