zoukankan      html  css  js  c++  java
  • 图像匹配-SSD

    任務:

      現在有兩來自於stereo-camera拍攝的兩幅圖像:

      左圖, flowers-left.png 右圖,flowers-right.png:

               

     現在在左圖中取一個大小爲100*100的patch.

     在右圖的strip中尋找匹配的patch.

    在此使用 ( sum of square differences )SSD算法進行匹配。也可以使用cross-correlation.

    Matlab 程序代碼:

    % Load images
    left = imread('imgs/flowers-left.png');
    right = imread('imgs/flowers-right.png');
    figure, imshow(left);
    figure, imshow(right);
    
    % Convert to grayscale, double, [0, 1] range for easier computation
    left_gray = double(rgb2gray(left)) / 255.0;
    right_gray = double(rgb2gray(right)) / 255.0;
    
    % Define image patch location (topleft [row col]) and size
    patch_loc = [120 170];
    patch_size = [100 100];
    
    % Extract patch (from left image)
    patch_left = left_gray(patch_loc(1):(patch_loc(1) + patch_size(1) - 1), patch_loc(2):(patch_loc(2) + patch_size(2) - 1));
    figure, imshow(patch_left);
    
    % Extract strip (from right image)
    strip_right = right_gray(patch_loc(1):(patch_loc(1) + patch_size(1) - 1), :);
    figure, imshow(strip_right);
    
    % Now look for the patch in the strip and report the best position (column index of topleft corner)
    best_x = find_best_match(patch_left, strip_right);
    disp(best_x);
    patch_right = right_gray(patch_loc(1):(patch_loc(1) + patch_size(1) - 1), best_x:(best_x + patch_size(2) - 1));
    figure, imshow(patch_right);
    
    % Find best match
    % Use sum of square differences (SSD), you could also use cross-correlation
    function best_x = find_best_match(patch, strip)
        % TODO: Find patch in strip and return column index (x value) of topleft corner
        best_x = 1; % placeholder
        min_diff = Inf;
        [row_strip, col_strip]=size(strip);
        [row_patch, col_patch]=size(patch);
        for x = 1:(col_strip - col_patch + 1 )
            other_patch = strip(:, x:(x + col_patch -1 ));
            diff = sum(sqrt((patch -other_patch).^2), 'all');
    %         diff = sumsq((patch - other_patch)(:)); %octave
            if diff < min_diff
                min_diff = diff;
                best_x = x;
            end
        end
    end
    

      

    結果:

      右圖爲在右圖中匹配等到的結果。

         

    新博客地址:www.ybliu.com
  • 相关阅读:
    删除了原有的offset之后再次启动会报错park Streaming from Kafka has error numRecords must not ...
    sparkStreaming消费kafka-1.0.1方式:direct方式(存储offset到Hbase)
    sparkStreaming消费kafka-1.0.1方式:direct方式(存储offset到zookeeper)
    进程的管理(五)-进程的实现
    进程管理(四)-进程的状态以及转换
    进程管理(三)-进程的层次
    numpy库的认识以及数组的创建
    进程管理(二)-进程的终止
    进程管理(一)-进程的概念以及进程的创建
    python爬取b站排行榜
  • 原文地址:https://www.cnblogs.com/yubao/p/12427349.html
Copyright © 2011-2022 走看看