FPGA Implementation image center differential transformation

  Difference image is the target image scene at successive time points constituted subtraction image, the differential image is defined as a broad target in the scene time point tk and tk + L is an image difference. Difference image is the image target scene in adjacent time points obtained phase reduction, thereby obtaining the target scene change over time.

  Difference image obtained in many areas a wide range of applications, such as: video compression, biomedical diagnostics, astronomy, remote sensing, face recognition and so on.

 

--FPGA open studio

A, MATLAB realization

 1, the main file img_diff.m

% ------------------------------------------------- ------------------------- 
% center differential transformation 
% -------------------- -------------------------------------------------- ---- 
CLC; 
Clear All; 
the RGB   = imread ( ' flower.bmp ' );         % read image 
Gray = rgb2gray (the RGB); 
Diff = mipcentraldiff (Gray, ' DX ' ); 

the subplot ( 2 , 2 , . 1 ) ; imshow (the RGB); title ( ' original ' ); 
the subplot ( 2 , 2 , . 3); imshow (Gray); title ( ' grayscale ' ); 
the subplot ( 2 , 2 , . 4 ); imshow (Diff); title ( ' center differential transformation ' );

2, sub-file mip1centraldiff.m

%--------------------------------------------------------------------------
%     img:          input image
%     direction:    'dx' or 'dy'
%     dimg:         resultant image
%--------------------------------------------------------------------------
function dimg = mipcentraldiff(img,direction)
img = padarray(img,[1,1],'symmetric','both');
[row,col] = size(img);
dimg = zeros(row,col);
switch(direction)
    case'dx',
        dimg(:,2:col-1)= (img(:,3:col)-img(:,1:col-2))/2;
    case'dy',
        dimg(2:row-1,:)= (img(3:row,:)-img(1:row-2,:))/2;
    otherwise
        disp('Direction is unknown');
end
dimg = dimg(2:end-1,2:end-1);

3, operating results

  Click Run in the master file img_diff.m, the following results were obtained:

 

Two, FPGA to achieve

  FPGA likewise be implemented using components Y gradation center differential transformation, how to implement the gray component Y, can view the presentation in front of the blog. We can change what type formula as follows:

  Ix = [I(x+2h) - I(x)] / 2h

  , H is 1, then the formula becomes the I X = [the I (X + 2) - the I (X)] / 2 

1, playing beat

  FPGA Implementation front and relief effect, as the pixel values ​​of the delay achieved by playing beat code is as follows:

//==========================================================================
//==                        打拍
//==========================================================================
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        {Y_de_r2,   Y_de_r1   } <= {1'b0,1'b0};
        {Y_hsync_r2,Y_hsync_r1} <= {1'b0,1'b0};
        {Y_vsync_r2,Y_vsync_r1} <= {1'b0,1'b0};
        {Y_data_r2, Y_data_r1 } <= {8'b0,8'b0};
    end
    else begin
        {Y_de_r2,   Y_de_r1   } <= {Y_de_r1,   Y_de   };
        {Y_hsync_r2,Y_hsync_r1} <= {Y_hsync_r1,Y_hsync};
        {Y_vsync_r2,Y_vsync_r1} <= {Y_vsync_r1,Y_vsync};
        {Y_data_r2, Y_data_r1 } <= {Y_data_r1, Y_data };
    end
end

2, the center differential transformation

  You can write code against the formula, divided by 2 operation we use the right one to achieve.

//==========================================================================
//==                        中心差分变换
//==========================================================================
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        diff_data <= 8'd0;
    end
    else begin
        diff_data <= (Y_data_r2 - Y_data) >> 1;
    end
end

3, signal synchronization

  The said many times before, directly after the hit signal out to take the assignment.

//==========================================================================
//==                        信号同步
//==========================================================================
assign diff_de = Y_de_r2;
assign diff_hsync = Y_hsync_r2;
assign diff_vsync = Y_vsync_r2;

 

Third, the verification plate

  Finally FPGA development board TFT screen, we get the following results:

  As can be seen from the results, in general, and MATLAB in effect the same, but there are subtle differences, because (Y_data_r2 - Y_data) calculation results may be negative, zero or one, if you want to reach perfection, must continue the transformation formula, the image transformation is relatively simple, do not want to waste thinking about this, interested students can try it yourself and see.

  Furthermore central difference algorithm may be converted to the RGB three-channel migration, to achieve color output of the center differential conversion.

 

References: [1] OpenS Lee: FPGA open chamber (Public No.)

 

Guess you like

Origin www.cnblogs.com/xianyufpga/p/12508424.html