Git Product home page Git Product logo

image_processing's Introduction

Image Processing

Finding an Electrical Element(BA3240) on a PCB with 2D Correlation.

Implementation

By converting images to grayscale, the computational complexity is reduced to a 2D dimension.

function B = rgb_to_gray(A)
    red = A(:,:,1);
    green = A(:,:,2);
    blue = A(:,:,3);
    
    B = 0.299 * red + 0.578 * green + 0.114 * blue;
end

To locate the IC on the PCB, a 2D correlation is employed, with its formula described below.

Additionally, the following code implements the aforementioned process.

function corr = corr_2d(x,y)
    sum_xy = sum(sum(x .* y));
    sum_x2 = sum(sum(x .* x));
    sum_y2 = sum(sum(y .* y));
    
    corr = sum_xy / sqrt(sum_x2 * sum_y2);
end

The provided code shifts the grayscale image of the IC from the top-left corner of the PCB and performs a comparison between the two images in each correlation section.

function M = corr_matrix(PCB,IC)
    [PCB_row,PCB_col] = size(PCB);
    [IC_row,IC_col] = size(IC);
    IC = double(IC);
    IC = IC - mean(IC,'all');
    M = zeros(PCB_row - IC_row + 1, PCB_col - IC_col + 1);
    for i=1:(PCB_row - IC_row + 1)
        for j=1:(PCB_col - IC_col + 1)
            PCB_cropped = double(PCB(i:i + IC_row - 1, j:j + IC_col - 1));
            PCB_cropped = PCB_cropped - mean(PCB_cropped,'all');
            M(i,j) = corr_2d(PCB_cropped,IC);
        end
    end
end

and the correlation diagram is shown below:

The graph's height indicates the degree of correlation between the two images, with the highest peaks observed at two locations that contain the IC. Based on the provided diagram, a threshold value of 0.75 has been set.

The entire process has also involved utilizing the rotated IC image to identify the rotated ICs on the PCB.

Finally, the matching result is displayed below:

image_processing's People

Contributors

fardinabbasi avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.