0

I am working on ridge frequency estimation for which I have to obtain an blockwise oriented image. I have developed the code but unable to remove an error.

the process goes like this. Input image is G(m,n) and theta(m,n) is an image containing theta. Input image G is divide into w*w block (w = 17) and for each block centred at pixel(i,j) compute an oriented window of size l*w (33*17). For each block we have to compute the x signature as

x[0],x[1],x[2].....x[l-1]...

x[k] = 1/w * summation(d=0 to w-1)G(u,v)

u = i+ (d-(w/2))cos(theta(i,j))+(k-(l/2))sin(theta(i,j))

v = i+ (d-(w/2))sin(theta(i,j))+((l/2)-k)cos(theta(i,j))

here is my code

% To compute ridge frequency
    theta_image;                theta image as input
    im = imread('cameraman.tif');
    [m,n] = size(im);
    l = (2*w-1);
    w = 17;
    ww = floor(w/2);

    for i1 = 9:w:m
        for j1 = 9:w:n
            G = im(i1-ww:i1+ww,j1-ww:j1+ww);
            O = theta(i1-ww:i1+ww,j1-ww:j1+ww);
            G = padarray(G,[10 10],'both');     not sure its correct?

            for k = 0:l-1
                for d = 0:w-1

                cnst_1 = (d-floor(w/2));
                cnst_2 = (k-floor(l/2));
                cnst_3 = (floor((l/2)-k);

                u = i1+(cnst_1.*cos(O(i1,j1)) + cnst_2.*sin(O(i1,j1)));
                v = j1+(cnst_1.*sin(O(i1,j1)) + cnst_3.*cos(O(i1,j1)));

                u = fix(u);
                v = fix(v);
                store(k,d) = G(u,v);

                x(k) = (sum(G(u,v)))/w;     not sure will it be stored block-wise?
                end;
            end;            
        end;
    end;

the error is

Attempted to access G(22,0); index must be a positive integer or logical.

Error in ridge_frequency (line 76)
                store(k,d) = G(u,v);
Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
Ritesh
  • 256
  • 2
  • 13
  • Do you have the Image Processing Toolbox? If so, [`blockproc`](http://www.mathworks.co.uk/help/images/ref/blockproc.html) would simplify things a fair bit. – Notlikethat Feb 08 '14 at 19:42
  • try `ceil` instead of `fix` because `fix` rounds a number towards zero. `ceil` will solve this problem but it may introduce other problems such as your index may go out of range. Watch out for that. Also, what is `ww`? – Autonomous Feb 09 '14 at 00:47
  • @Notlikethat.i have to avoid using blockproc..so is there any other logic and how to remove the above mentioned error..plz help.. – Ritesh Feb 09 '14 at 06:51
  • @Parag..ww is the floor(w/2) i.e for w = 17 ,ww= 8..so that i can move within block at center pixel..for center (9,9) movement within block would be (9-8:9+8,9-8:9+8).. – Ritesh Feb 09 '14 at 06:55

0 Answers0