├── .gitignore ├── MHCFRTF_1 └── atan2_cordic.slx ├── README.md ├── canny ├── canny.m ├── cannyHDL_2018a.slx ├── cannyHDL_2019b.slx ├── parameters.m └── rhions.png ├── integralImage ├── img_test.png ├── integralImage_hdl_2018b.slx └── myIntegralImage.m ├── qr8x8 └── qr8x8.slx ├── rgb2grey ├── img_test_rgb.png └── rgb2gray_2018b.slx ├── rgb2grey_hw └── rgb2grey_hw.slx ├── sobel ├── sobel.m ├── sobel_hdl_2018b.slx ├── sobel_hdl_2019a.slx └── test_1080p.bmp └── sumiao ├── sumiao_720p.jpg ├── sumiao_github.slx ├── sumiao_result.jpg └── sumiao_zed.slx /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /MHCFRTF_1/atan2_cordic.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/MHCFRTF_1/atan2_cordic.slx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # matlab_visionhdl 2 | MATLAB Vision HDL 3 | 4 | System requirement: MATLAB 2018b, HDL Coder Toolbox, Vision HDL Toolbox 5 | 6 | Index 7 | MHCFRTF - MATLAB HDL Coder from Rumen to Fanche 8 | 9 | rgb2grey - Introduction to Algorithm Implementation using Simulink and Vision HDL Toolbox 10 | 11 | rgb2grey_hw - Hardware Implementation of rgb2grey algorithm using HDL Coder workflow 12 | 13 | sumiao - Image to pencil paint style picture using HDL Coder and its' verification on FPGA 14 | 15 | integralImage - integral image implementation using Simulink + Vision HDL Toolbox + HDL Coder Toolbox 16 | 17 | canny - canny edge detector implementation using Simulink + Vision HDL Toolbox + HDL Coder Toolbox 18 | -------------------------------------------------------------------------------- /canny/canny.m: -------------------------------------------------------------------------------- 1 | img = imread('rhions.png'); 2 | img = im2double(img); 3 | 4 | kernel1 = [1 4 7 4 1; 5 | 4 16 26 16 4; 6 | 7 26 41 26 7; 7 | 4 16 26 16 4; 8 | 1 4 7 4 1;]/273; 9 | 10 | kernel2 = [2 4 5 4 2; 11 | 4 9 12 9 4; 12 | 5 12 15 12 5; 13 | 4 9 12 9 4; 14 | 2 4 5 4 2]/115; 15 | %img = imfilter(img, kernel2, 'symmetric', 'conv'); 16 | img_gaussian = conv2(img, rot90(kernel1,2),'same'); 17 | %img_gaussian_ref = img_gaussian(3:242,3:322); 18 | %imshow(img_gaussian),title('image after gaussian filter'); 19 | 20 | %% sobel 21 | Gx_kernel = fspecial('sobel'); 22 | Gy_kernel = Gx_kernel'; 23 | Gx_kernel=[-1 0 1; 24 | -2 0 2; 25 | -1 0 1]; 26 | Gy_kernel=[1 2 1; 27 | 0 0 0; 28 | -1 -2 -1]; 29 | Gx = conv2(img_gaussian,rot90(Gx_kernel,2),'same'); 30 | Gy = conv2(img_gaussian,rot90(Gy_kernel,2),'same'); 31 | img_sobel = abs(Gx)+abs(Gy); 32 | figure; 33 | imshow(img_sobel),title('image after sobel filter'); 34 | 35 | 36 | [M,N] = size(img_sobel); 37 | img_theta = zeros(M,N); 38 | img_theta1 = zeros(M,N); 39 | img_theta2 = zeros(M,N); 40 | img_theta3 = zeros(M,N); 41 | temp_array = zeros(M,N); 42 | for i = 1:M 43 | for j = 1:N 44 | temp = atan2(Gy(i,j),Gx(i,j)); 45 | temp_array(i,j) = temp; 46 | if temp<-pi/2 47 | img_theta(i,j) = temp+pi; 48 | elseif temp>pi/2 49 | img_theta(i,j) = temp-pi; 50 | else 51 | img_theta(i,j) = temp; 52 | end 53 | end 54 | end 55 | img_theta1 = img_theta*180/pi; 56 | for i = 1:M 57 | for j = 1:N 58 | if img_theta1(i,j)<0 59 | img_theta2(i,j) = img_theta1(i,j)-90; 60 | img_theta2(i,j) = abs(img_theta2(i,j)); 61 | else 62 | img_theta2(i,j) = img_theta1(i,j); 63 | end 64 | end 65 | end 66 | 67 | alt_img_theta2 = zeros(M,N); 68 | for i = 1:M 69 | for j = 1:N 70 | if img_theta(i,j)<0 71 | alt_img_theta2(i,j) = img_theta(i,j)-pi/2; 72 | alt_img_theta2(i,j) = abs(alt_img_theta2(i,j)); 73 | else 74 | alt_img_theta2(i,j) = img_theta(i,j); 75 | end 76 | end 77 | end 78 | alt_img_theta2 = alt_img_theta2*180/pi; 79 | 80 | for i=1:M 81 | for j=1:N 82 | if ((0 patch(4)) && (patch(5) > patch(6))) 113 | img_nms(i-1,j-1) = patch(5); 114 | end 115 | case 45 116 | if ((patch(5) > patch(3)) && (patch(5) > patch(7))) 117 | img_nms(i-1,j-1) = patch(5); 118 | end 119 | case 0 120 | if ((patch(5) > patch(2)) && (patch(5) > patch(8))) 121 | img_nms(i-1,j-1) = patch(5); 122 | end 123 | case 135 124 | if ((patch(5) > patch(1)) && (patch(5) > patch(9))) 125 | img_nms(i-1,j-1) = patch(5); 126 | end 127 | end 128 | end 129 | end 130 | img_nms=im2uint8(img_nms); 131 | figure; 132 | imshow(img_nms),title('image after nms'); 133 | %% double threshold 134 | [M,N] = size(img_nms); 135 | img_dth = zeros(M,N,'logical'); 136 | minVal = 80; 137 | maxVal = 100; 138 | 139 | for i = 1:M-2 140 | for j = 1:N-2 141 | if img_nms(i,j) > maxVal 142 | img_dth(i,j) = true; 143 | elseif img_nms(i,j) > minVal 144 | patch = (img_nms(i:i+2,j:j+2)>maxVal); 145 | patch2 = img_dth(i:i+2,j:j+2); 146 | if sum(sum(patch))>0 || sum(sum(patch2))>0 147 | img_dth(i,j) = true; 148 | end 149 | end 150 | end 151 | end 152 | figure; 153 | imshow(img_dth); -------------------------------------------------------------------------------- /canny/cannyHDL_2018a.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/canny/cannyHDL_2018a.slx -------------------------------------------------------------------------------- /canny/cannyHDL_2019b.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/canny/cannyHDL_2019b.slx -------------------------------------------------------------------------------- /canny/parameters.m: -------------------------------------------------------------------------------- 1 | kernel = [1 4 7 4 1; 2 | 4 16 26 16 4; 3 | 7 26 41 26 7; 4 | 4 16 26 16 4; 5 | 1 4 7 4 1;]/273; 6 | 7 | Gx_kernel=[-1 0 1; 8 | -2 0 2; 9 | -1 0 1]; 10 | Gy_kernel=[1 2 1; 11 | 0 0 0; 12 | -1 -2 -1]; 13 | 14 | totalPixels = 320*402; 15 | 16 | minVal = 80; 17 | maxVal = 100; -------------------------------------------------------------------------------- /canny/rhions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/canny/rhions.png -------------------------------------------------------------------------------- /integralImage/img_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/integralImage/img_test.png -------------------------------------------------------------------------------- /integralImage/integralImage_hdl_2018b.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/integralImage/integralImage_hdl_2018b.slx -------------------------------------------------------------------------------- /integralImage/myIntegralImage.m: -------------------------------------------------------------------------------- 1 | img = imread('img_test.png'); 2 | 3 | if size(img,3) == 3 4 | img = rgb2gray(img); 5 | end 6 | 7 | % reference 8 | IntegralImage_ref = integralImage(img); 9 | 10 | % DUT 11 | img_double = im2double(img)*255; 12 | 13 | [M, N] = size(img); 14 | lineTemp = zeros(1,N); 15 | IntegralImage_dut = zeros(M,N); 16 | pixelAccum_DBG = zeros(M,N); 17 | 18 | for i = 1:M 19 | pixelAccum = 0; 20 | for j = 1:N 21 | pixelAccum = img_double(i,j) + pixelAccum; 22 | lineTemp(j) = pixelAccum + lineTemp(j); 23 | pixelAccum_DBG(i,j) = pixelAccum; 24 | end 25 | if i ==4 26 | disp(' '); 27 | end 28 | IntegralImage_dut(i,:) = lineTemp; 29 | end 30 | 31 | if sum(sum(IntegralImage_ref(2:M+1,2:N+1)==IntegralImage_dut)) == M*N 32 | disp('test pass!'); 33 | else 34 | disp('test fail!'); 35 | end 36 | 37 | 38 | integralImage_HDL = get(out.integralImage_HDL,'Data'); 39 | integralImage_HDL = reshape(integralImage_HDL,[320 240])'; 40 | sum(sum(IntegralImage_ref(2:M+1,2:N+1)==double(integralImage_HDL))) == M*N -------------------------------------------------------------------------------- /qr8x8/qr8x8.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/qr8x8/qr8x8.slx -------------------------------------------------------------------------------- /rgb2grey/img_test_rgb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/rgb2grey/img_test_rgb.png -------------------------------------------------------------------------------- /rgb2grey/rgb2gray_2018b.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/rgb2grey/rgb2gray_2018b.slx -------------------------------------------------------------------------------- /rgb2grey_hw/rgb2grey_hw.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/rgb2grey_hw/rgb2grey_hw.slx -------------------------------------------------------------------------------- /sobel/sobel.m: -------------------------------------------------------------------------------- 1 | % v = VideoReader('rhinos.avi'); 2 | % img = rgb2gray(readFrame(v)); 3 | 4 | img = imread('test_1080p.bmp'); 5 | [M,N,~] = size(img); 6 | 7 | img_gray = zeros(M,N); 8 | for i = 1:M 9 | for j = 1:N 10 | gray_val = (66 * double(img(i,j,1)) + ... 11 | 129 * double(img(i,j,2)) + ... 12 | 25 * double(img(i,j,3)) + ... 13 | 128); 14 | img_gray(i,j) = bitshift(gray_val, -8) + 16; 15 | end 16 | end 17 | img = uint8(img_gray); 18 | 19 | %imshow(uint8(img_gray)) 20 | 21 | %img = rgb2gray(img); 22 | 23 | 24 | 25 | % sobel kernel 26 | Gx = [-1 0 1; 27 | -2 0 2 28 | -1 0 1]; 29 | Gy = [ 1 2 1; 30 | 0 0 0 31 | -1 -2 -1]; 32 | 33 | % padding - symmetric 34 | img_pad = zeros(M+2,N+2); 35 | img_pad(2:M+1,2:N+1) = img; 36 | img_pad(1,:) = img_pad(2,:); 37 | img_pad(M+2,:) = img_pad(M+1,:); 38 | img_pad(:,1) = img_pad(:,2); 39 | img_pad(:,N+2) = img_pad(:,N+1); 40 | 41 | % filter 42 | img_sobel = zeros(M,N,'uint8'); 43 | img_sobel_test = zeros(M,N,'uint8'); 44 | for i = 2:M+1 45 | for j = 2:N+1 46 | patch = img_pad(i-1:i+1,j-1:j+1); 47 | img_Gx = sum(sum(patch.*Gx)); 48 | img_Gy = sum(sum(patch.*Gy)); 49 | img_sobel(i-1,j-1) = abs(img_Gx) + abs(img_Gy); 50 | 51 | if i == 438+1 && j == 9+1 52 | disp(); 53 | end 54 | 55 | edge_val = 255-uint8(img_sobel(i-1,j-1)); 56 | if (edge_val > 200) 57 | edge_val = 255; 58 | elseif (edge_val < 100) 59 | edge_val = 0; 60 | end 61 | img_sobel_test(i-1,j-1) = edge_val; 62 | end 63 | end 64 | 65 | img_sobel_test_rgb = zeros(M,N,3,'uint8'); 66 | img_sobel_test_rgb(:,:,1) = img_sobel_test; 67 | img_sobel_test_rgb(:,:,2) = img_sobel_test; 68 | img_sobel_test_rgb(:,:,3) = img_sobel_test; 69 | imshow(img_sobel_test_rgb) 70 | 71 | img_sobel_test_r = img_sobel_test; 72 | img_xilinx = imread('result_1080p_golden.bmp'); 73 | img_xilinx_r = img_xilinx(:,:,1); 74 | -------------------------------------------------------------------------------- /sobel/sobel_hdl_2018b.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/sobel/sobel_hdl_2018b.slx -------------------------------------------------------------------------------- /sobel/sobel_hdl_2019a.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/sobel/sobel_hdl_2019a.slx -------------------------------------------------------------------------------- /sobel/test_1080p.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/sobel/test_1080p.bmp -------------------------------------------------------------------------------- /sumiao/sumiao_720p.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/sumiao/sumiao_720p.jpg -------------------------------------------------------------------------------- /sumiao/sumiao_github.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/sumiao/sumiao_github.slx -------------------------------------------------------------------------------- /sumiao/sumiao_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/sumiao/sumiao_result.jpg -------------------------------------------------------------------------------- /sumiao/sumiao_zed.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linbaiwpi/matlab_visionhdl/46c741d42e2c5b0012d28846de19f1ad601851ca/sumiao/sumiao_zed.slx --------------------------------------------------------------------------------