Tool/software:
I am using the MATLAB script for correcting an LDC image.
Lens distortion correction looks good in the first place, but straight lines look wobbly.
How to improve this issue?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi Jianzhong
Below is the script and settings I used
s = 1.15; m = 4; pitch_in_mm = 0.0021; f_in_mm = 4; W = 3840; H = 2160; hc = W/2; vc = H/2; Wmesh = ceil(W / 2^m) * 2^m; Hmesh = ceil(H / 2^m) * 2^m; gen_lut("spec_file.txt", pitch_in_mm, f_in_mm, Wmesh, Hmesh, hc, vc, s, m); function [] = gen_lut(spec_file, pitch_in_mm,f_in_mm, W, H, hc, vc,s ,m) f = f_in_mm/pitch_in_mm ; [h_p , v_p] = meshgrid( 0:W, 0:H); [h_d,v_d] = xyz2distorted(h_p,v_p, f/s, hc, vc,spec_file, pitch_in_mm); h_delta = round((h_d-h_p) * 8); v_delta = round((v_d-v_p) * 8); mh = h_delta(1:2^m:end, 1:2^m:end)'; mv = v_delta(1:2^m:end, 1:2^m:end)'; dlmwrite('mesh.txt', [mh(:), mv(:)], 'delimiter', ' '); end function [h_d, v_d] = xyz2distorted(x, y, z, hc, vc, spec_file, pitch_in_mm) [phi, r] = cart2pol(x-hc, y-vc); theta = atan2(r, z); lut = read_spec(spec_file, pitch_in_mm); r = interp1(lut(:,1), lut(:,2), theta); [h_d, v_d] = pol2cart(phi, r); h_d = h_d + hc; v_d = v_d + vc; end function lut = read_spec(spec_file, pitch_in_mm) lut0 = dlmread(spec_file); theta = lut0(:,1)/180*pi; lut = [theta, lut0(:,2)/pitch_in_mm]; end
0.00 0.00 0.80 0.06 1.60 0.11 2.41 0.17 3.21 0.22 4.01 0.28 4.81 0.34 5.62 0.39 6.42 0.45 7.22 0.51 8.02 0.56 8.83 0.62 9.63 0.68 10.43 0.73 11.23 0.79 12.03 0.85 12.84 0.91 13.64 0.97 14.44 1.03 15.24 1.09 16.05 1.15 16.85 1.21 17.65 1.27 18.45 1.33 19.25 1.39 20.06 1.46 20.86 1.52 21.66 1.58 22.46 1.65 23.27 1.72 24.07 1.78 24.87 1.85 25.67 1.92 26.48 1.99 27.28 2.06 28.08 2.13 28.88 2.20 29.68 2.27 30.49 2.35 31.29 2.42 32.09 2.50 32.89 2.58 33.70 2.66 34.50 2.74 35.30 2.82 36.10 2.91 36.91 3.00 37.71 3.08 38.51 3.17 39.31 3.27 40.11 3.36 40.92 3.46 41.72 3.56 42.52 3.66 43.32 3.76 44.13 3.87 44.93 3.98 45.73 4.09 46.53 4.21 47.34 4.33 48.14 4.45 48.94 4.58 49.74 4.71 50.54 4.85 51.35 4.99 52.15 5.13 52.95 5.28 53.75 5.44 54.56 5.60 55.36 5.77 56.16 5.95 56.96 6.13 57.76 6.33 58.57 6.53 59.37 6.74 60.17 6.96 60.97 7.19 61.78 7.43 62.58 7.69 63.38 7.96 64.18 8.25 64.99 8.55 65.79 8.87 66.59 9.21 67.39 9.58 68.19 9.97 69.00 10.39 69.80 10.84 70.60 11.33 71.40 11.86 72.21 12.43 73.01 13.05 73.81 13.74 74.61 14.49 75.42 15.33 76.22 16.26 77.02 17.31 77.82 18.48 78.62 19.83 79.43 21.37 80.23 23.16
<?xml version="1.0" encoding="utf-8"?> <cfg_ldc_xml xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <!--this is a comment--> <dcc_name>cfg_ldc</dcc_name> <dcc_header> <camera_module_id> 823 </camera_module_id> <dcc_descriptor_id> 5 </dcc_descriptor_id> <algorithm_vendor_id> 1 </algorithm_vendor_id> <tunning_tool_version> 0 </tunning_tool_version> </dcc_header> <!--=======================================================================--> <typedef> <cfg_ldc_vars type="struct"> <ldc_en type="uint16"> </ldc_en> <ldc_ldmapen type="uint16"> </ldc_ldmapen> <ldc_datamode type="uint16"> </ldc_datamode> <ldc_opdatamode type="uint16"> </ldc_opdatamode> <ldc_ip_dfmt type="uint16"> </ldc_ip_dfmt> <ldc_pwarpen type="uint16"> </ldc_pwarpen> <ldc_yint_typ type="uint16"> </ldc_yint_typ> <ldc_regmode_en type="uint16"> </ldc_regmode_en> <ldc_meshtable_m type="uint16"> </ldc_meshtable_m> <ldc_mesh_frsz_w type="uint16"> </ldc_mesh_frsz_w> <ldc_mesh_frsz_h type="uint16"> </ldc_mesh_frsz_h> <ldc_compute_frsz_w type="uint16"> </ldc_compute_frsz_w> <ldc_compute_frsz_h type="uint16"> </ldc_compute_frsz_h> <ldc_initx type="uint16"> </ldc_initx> <ldc_inity type="uint16"> </ldc_inity> <ldc_input_frsz_w type="uint16"> </ldc_input_frsz_w> <ldc_input_frsz_h type="uint16"> </ldc_input_frsz_h> <ldc_obw type="uint16"> </ldc_obw> <ldc_obh type="uint16"> </ldc_obh> <ldc_pixpad type="uint16"> </ldc_pixpad> <ldc_a type="int16"> </ldc_a> <ldc_b type="int16"> </ldc_b> <ldc_c type="int16"> </ldc_c> <ldc_d type="int16"> </ldc_d> <ldc_e type="int16"> </ldc_e> <ldc_f type="int16"> </ldc_f> <ldc_g type="int16"> </ldc_g> <ldc_h type="int16"> </ldc_h> <ldc_sf_width type="uint16[3]"> </ldc_sf_width> <ldc_sf_height type="uint16[3]"> </ldc_sf_height> <ldc_sf_en type="uint16[3][3]"> </ldc_sf_en> <ldc_sf_obw type="uint16[3][3]"> </ldc_sf_obw> <ldc_sf_obh type="uint16[3][3]"> </ldc_sf_obh> <ldc_sf_pad type="uint16[3][3]"> </ldc_sf_pad> <ldc_ylut_en type="uint16"> </ldc_ylut_en> <ldc_yin_bitdpth type="uint16"> </ldc_yin_bitdpth> <ldc_yout_bitdpth type="uint16"> </ldc_yout_bitdpth> <ldc_clut_en type="uint16"> </ldc_clut_en> <ldc_cin_bitdpth type="uint16"> </ldc_cin_bitdpth> <ldc_cout_bitdpth type="uint16"> </ldc_cout_bitdpth> <ldc_y_lut type="uint16[513]"> </ldc_y_lut> <ldc_c_lut type="uint16[513]"> </ldc_c_lut> <mesh_table_pitch_in_bytes type="uint32"> </mesh_table_pitch_in_bytes> <mesh_table_size type="uint32"> </mesh_table_size> <mesh_lut type="uint16*"> </mesh_lut> <chroma_ctl_en type="uint16"> </chroma_ctl_en> <chroma_ctl_format type="uint16"> </chroma_ctl_format> </cfg_ldc_vars> </typedef> <!--=======================================================================--> <use_case val="65535"> <n-space> <region0 class="0"> <exposure val="1" min="0" max="2000000"> </exposure> <gain val="0" min="0" max="100000"> </gain> </region0> </n-space> <parameter_package> <ldc_dcc type="cfg_ldc_vars"> { 1 // LDC_CTRL LDC_EN LDC Enable, 0: Disable, 1: Enable 1 // LDC_CTRL LDMAPEN LD Mapping enable, 0: disable, 1: enable 4 // LDC_CTRL DATAMODE Input data mode, 0: UYVY, 1: Y only, 2: YUV420SP, 3: UV only, 4: YUV422SP, 5: Y1+Y2, 6: Y1 + Y2Y3 0 // LDC_CTRL OP_DATAMODE Output data mode, 0: keep UYVY; 1: convert to 420 2 // LDC_CTRL IP_DFMT Input pixel format, 0: 8b, 1: 12b packed, 2: 12b unpacked 1 // LDC_CTRL PWARPEN 0: Disable perspective warp. 1: Enable perspective warp 1 // LDC_CFG YINT_TYP Interpolation type for Y data. 0: Bicubic, 1: Bilinear 0 // LDC_CFG REGMODE_EN Region mode, 0: disable, 1: enable 4 // LDC_MESHTABLE_CFG M Mesh table subsampling factor (0-7) 3840 // LDC_MESH_FRSZ W Mesh frame width (0-8192) 2160 // LDC_MESH_FRSZ H Mesh frame height (0-8192) 3840 // LDC_COMPUTE_FRSZ W Compute width (0-8192) 2160 // LDC_COMPUTE_FRSZ H Compute height (0-8192) 0 // LDC_INITXY INITX Output starting horizontal coordinate (0-8192) 0 // LDC_INITXY INITY Output starting vertical coordinate (0-8192) 3840 // LDC_INPUT_FRSZ W Input frame width 2160 // LDC_INPUT_FRSZ H Input frame height 16 // LDC_BLOCK_SIZE OBW Output block width (0-255) 16 // LDC_BLOCK_SIZE OBH Output block height (0-255) 1 // LDC_BLOCK_SIZE PIXPAD Pixel pad (0-15) 4096 // LDC_AB A Affine Transform warp, A S16Q12 0 // LDC_AB B Affine Transform warp, B S16Q12 0 // LDC_CD C Affine Transform warp, C S16Q3 0 // LDC_CD D Affine Transform warp, D S16Q12 4096 // LDC_EF E Affine Transform warp, E S16Q12 0 // LDC_EF F Affine Transform warp, F S16Q3 0 // LDC_GH G Affine Transform warp, G S16Q23 0 // LDC_GH H Affine Transform warp, H S16Q23 {0, 0, 0} //ldc_sf_width [3] {0, 0, 0} //ldc_sf_height[3] {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} //ldc_sf_en [3][3] {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} //ldc_sf_obw[3][3] {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} //ldc_sf_obh[3][3] {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} //ldc_sf_pad[3][3] 0 // LDC_DUALOUT_CFG YLUT_EN Luma LUT enable (0-1) 8 // LDC_DUALOUT_CFG YIN_BITDPTH Luma input bit depth (8-12) 8 // LDC_DUALOUT_CFG YOUT_BITDPTH Luma output bit depth (8-12) 0 // LDC_DUALOUT_CFG CLUT_EN Chroma LUT enable (0-1) 8 // LDC_DUALOUT_CFG CIN_BITDPTH Chroma input bit depth (8-12) 8 // LDC_DUALOUT_CFG COUT_BITDPTH Chroma output bit depth (8-12) { //y_lut 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } 976, //mesh_table_pitch_in_bytes 66368, //mesh_table_size { //mesh_lut #include "ar0823_mesh_lut.txt" } 1 // LDC_CTRL CH_CHANCTRL_EN Chroma control enable, 0: disable, 1: enable 0 // LDC_CTRL CH_IP_DFMT Chroma pixel formats, 0: 8b, 1: 12b packet, 2: 12b unpacked } </ldc_dcc> </parameter_package> </use_case> <!--=====================================================================--> </cfg_ldc_xml>