Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Computing the local maximum and minimum in process of extracting SIFT features.

Subject: Computing the local maximum and minimum in process of extracting SIFT features.

From: Aniket Deshmukh

Date: 14 Nov, 2012 15:44:18

Message: 1 of 2

Hello,
I am trying to extract SIFT features for an Image. In the process we need to find the local maximum and minimum.
So, I wrote a function which computes them. But it is computationally intensive. Will you please go through my algorithm to reduce time of execution.

The function given above will take in a matrix which is of size, lets say 512X512X4. Basically these are 4 images blurred with different Gaussian of different variances. Now we take the second image (:,:,2), the image above - (:,:,1) and the image below (:,:,3). Take a pixel, get the neighborhood of 3x3 pixels around the current pixel. Take a neighborhood of 3x3 in the image just above and below the current image. Then we need to check whether the current pixel is the maximum or minimum considering all the neighborhoods taken. Then another 3 images are taken (:,:,3) - main image, an image above (:,:,2) and an image below (:,:,4). Now the process is repeated for all the images in the present image (:,:,3).

Following is the function I wrote:
%The "dog_mat" is the matrix of size 512x512x4
%The max_min is the output matrix
function [ max_min ] = get_maxmin( dog_mat )

dog_mat = double(dog_mat);
[r c n] = size(dog_mat);
disp(n);
max_min = zeros(r,c,n-2);

%Loop for getting the max and min for the two matrices (:,:,2) and (:,:,3)
for frames = 2:n-1
    p_up = dog_mat(:,:,frames+1); %The top matrix
    p_down = dog_mat(:,:,frames-1); %The Bottom MAtrix
    p = dog_mat(:,:,frames); %The current matrix
    for i = 1:r-1
        for j = 1:c-1

%Getting the proper neighborhood about the required pixel

            if (i == 1) && (j == 1)
                neighbours = [p(1,2),p(2,2),p(2,1),p_up(1,1),p_up(1,2),p_up(2,1),p_down(2,2),p_down(1,1),p_down(1,2),p_down(2,1),p_down(2,2)];
                if (p(i,j) >= max(neighbours) | p(i,j) <= min(neighbours))
                    max_min(i,j,frames-1) = p(i,j);
                end
            end
            if (i > 1) && (i < r) && (j == 1)
                neighbours = [p(i-1:i+1,j:j+1),p_up(i-1:i+1,j:j+1),p_down(i-1:i+1,j:j+1)];
                if (p(i,j) == max(neighbours) | p(i,j) == min(neighbours))
                    max_min(i,j,frames-1) = p(i,j);
                end
            end
            if (i == 1) && (j > 1) && (j < c)
                neighbours = [p(i:i+1,j-1:j+1),p_up(i:i+1,j-1:j+1),p_down(i:i+1,j-1:j+1)];
                if (p(i,j) == max(neighbours) | p(i,j) == min(neighbours))
                    max_min(i,j,frames-1) = p(i,j);
                end
            end
            if (i > 1) && (j > 1) && (i < r) && (j < c)
                neighbours = [p(i-1:i+1,j-1:j+1),p_up(i-1:i+1,j-1:j+1),p_down(i-1:i+1,j-1:j+1)];
                if (p(i,j) >= max(neighbours) | p(i,j) <= min(neighbours))
                    max_min(i,j,frames-1) = p(i,j);
                end
            end
        end
    end
end

The problem with this function is it is running for 10-20 sec for each "dog_mat". There are three other "dog_mat" which should be analyzed to get the local maxima and minima and the final process is taking 30 seconds which is huge amount.

Will you please help me in writing optimized code? It would be very helpful. Even if you have slightest idea please post it here...
Thank You in advance! :)

Subject: Computing the local maximum and minimum in process of extracting

From: dovariswaraj@gmail.com

Date: 28 Mar, 2014 10:28:19

Message: 2 of 2

my marix size is 225*225*3 how can implement local maxima and minima in SIFT algoritham ... ..in your code i got error like this....

"Expected a scalar. Non-scalars are not supported in IF or WHILE statements, or with logical operators. Instead, use ALL to convert matrix logicals to their scalar equivalents"

how can over come and how can implement SIFT ALORITHAM IN simulink....
upto DIFFRENCE OF GUSSIAN (DOG) I DO..

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us