Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Comparing Images

Options
  • 27-11-2002 3:04pm
    #1
    Closed Accounts Posts: 1,651 ✭✭✭


    Hey,

    Does anyone know of any tools that I could use to programatically compare two gif images?

    I want to compare the 5 day swell forecast chart with the 0 day forecast chart in five days time.

    So I want to download the file eurwam120.gif which is the forecast for (now + 120 hours). Then in 120 hours download eurwam00.gif which is now (in 120 hours at least) and compare the two.
    Obviously they won't be identical but there's got to be a way of seeing if they are somewhat similar?


    Like a diff but getting a percentage of similarity in return.

    Any ideas? Apart from going and writing it myself :)

    Thanks


Comments

  • Closed Accounts Posts: 358 ✭✭CH


    matlab has a very good image processing toolbox, and theres alot of help on the net too.

    The 2 files below will return the correlation between 2 images... 1 meaning the images are idenitcal. It'll also plot a histogram of each image for visual comparison.

    main.m
    close all;
    clear all;
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % get images
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    f_orig = double(imread('IMAGE_ONE.tif'));
    g_orig = double(imread('IMAGE_TWO.tif'));
    
    colormap(gray);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % normalize
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    f = f_orig/(norm(f_orig, 'fro'));
    g = g_orig/(norm(g_orig, 'fro'));
    f2 = f;
    g2 = g;
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % compute fft and correlate
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [corr2] = corrfft(f2, g2);
    % print out how much correlation we have
    corr2
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % plot
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    I_f = f_orig/256;
    I_g = g_orig/256;
    
    % draw image 1
    figure(1);
    subplot(3,2,1);
    imagesc(f)
    axis('square')
    
    % draw histogram 1
    subplot(3,2,2);
    imhist(I_f);
    colorbar;
    
    % draw image 2
    colormap(gray)
    subplot(3,2,3);
    imagesc(g)
    axis('square')
    
    % draw histogram 2
    subplot(3,2,4);
    imhist(I_g);
    colorbar;
    
    % draw histogram 2
    subplot(3,2,6);
    plot(corr2,'--rs', 'MarkerEdgeColor','k', 'MarkerFaceColor','g', 'MarkerSize',4)
    title('correlation: 0-1')
    % eof
    


    corrfft.m
    function [corr] = corrfft(f, g)
    
    sze = size(f);
    sze = sze(1);
    
    % compute fft of f and g zero padded out to 2*sze x 2*sze
    f = flipud(fliplr(f));
    ffft = fft2(f, sze*2, sze*2);
    gfft = fft2(g, sze*2, sze*2);
    
    yout  = ifft2(ffft.*gfft);
    
    startpt = sze/2 + 1;
    endpt = sze*2 - sze/2;
    h = yout(startpt,:);
    for i = (startpt+1):endpt
        h = [h; yout(i,:)];
    end
    yout = h(:,startpt);
    for i = (startpt+1):endpt
        yout = [yout h(:,i)];
    end
    y = yout;
    corr = max(max(y));
    % eof
    


    [edit]god damn :) comes out as smilies =)[/edit]


  • Closed Accounts Posts: 14,483 ✭✭✭✭daveirl


    This post has been deleted.


  • Registered Users Posts: 1,038 ✭✭✭rob1891


    you could script gimp to get the two images separate layers and "add" or "multiply" or "subtract" or "which ever one makes it look the way you want it to".

    It has some kind of batch mode operation that might facilitate such scripting, sounds like overkill of course.

    rob


  • Closed Accounts Posts: 304 ✭✭Zaltais


    Imagemagick has API's in Perl, C, C++, Java, Python, VB and others, and has a built in compare function, which compares images (surprising that)....

    I've never used this exact function though, so I've no idea what sort of output it gives...

    If you want, send me a PM, and I'll give you my e-mail address - you send me the images, and I'll run the compare function and see what kind of result i get....

    Cheers,

    Zaltais


Advertisement