PHAY0021 THE PROCESS OF DRUG DEVELOPMENT 2023Java

Java Python PHAY0021

THE PROCESS OF DRUG DEVELOPMENT (TPODD 2)

May 2023

1. Answer ALL parts of the question

Asthma medications are usually administered via inhalation. Your company has developed both an inhaler and a tablet containing the same active compound X. The company would like to release the tablet on the market, so you are asked to compare the effect of the tablet with that after inhalation.

It was determined that the area under curve (AUC) of 1 mg of X administered via inhalation is 20 mg h/L. The AUC of a 5 mg X tablet is 60 mg h/L.

a) How does the bioavailability of inhalation compare to the tablet?             (5% of marks)

b) Explain which parameters affect the bioavailability of the tablet.            (10% of marks)

You are asked to design a preclinical animal study to evaluate possible oral administration of a higher dose of compound X.

c) Describe which study you would perform. Your answer should include a discussion of the possible practical issues related to the selected route of administration.          (55% of marks)

Following a sub-chronic repeated dose study, you are asked to evaluate the weights of liver, spleen and kidneys after the post mortem analysis of the rats.

d) From the available data, identify the no-observed-adverse-effect level (NOAEL). Justify your answer.   (10% of marks)

e) Considering all the data available so far, which route of administration would you propose to use and why?   (20% of marks)

2. Answer ALL parts of the question

Tacrolimus is an immunosuppressant drug that is used in combination with other medicines to prevent rejection following a kidney, heart, liver, or lung transplant, with blood concentrations over 15 mg/ml found to be toxic. Tacrolimus is predominantly metabolized by CYP3A4 and CYP3A5.

a) Briefly explain the overall function of CYP proteins and name two major isoforms of this pro PHAY0021 THE PROCESS OF DRUG DEVELOPMENT 2023Java tein family.  (15% of marks)

b) Please explain possible risks of co-administering tacrolimus with other drugs, or ingesting grapefruit juice after tacrolimus administration. You may use a drawing to support your explanation.   (25% of marks)

c) Describe two modifications to the tacrolimus structure that can occur during metabolism. Using the heavy atom numbering in the tacrolimus structure shown above, provide three specific sites where these reactions could take place.   (40% of marks)

d) Please briefly explain an assay to evaluate if a compound can act as an inhibitor of one of the main CYP isoforms and provide reasonable classification bands for potent, moderate and weak inhibition.   (20% of marks)

3. Answer ALL parts of the question

a) Explain which physicochemical parameters of molecules are important to determine their developability and enhance the probability of success during the clinical trials.   (25% of marks)

b) Why is the aqueous solubility of a new candidate molecule important?   (25% of marks)

c) How can you measure the solubility of a compound and how does it relate to its chemical structure, lipophilicity, pKa and absorption?    (15% of marks)

d) Discuss how chemical modification can be considered to increase the aqueous solubility of a drug discovery compound during lead optimisation.   (35% of marks)

4. Answer BOTH parts of the question

In recent months several pharma companies have withdrawn drugs that were originally approved by accelerated approval pathways. For example, GSK recently withdrew Blenrep, which had received FDA accelerated approval in 2020, because it was proven to be ineffective as a monotherapy in confirmatory trials.

a) Discuss the regulatory initiatives in place for drugs to receive accelerated approval and explain why such late withdrawals after approval can occur.   (50% of marks)

b) Outline the current strategies being adopted to reduce failure and improve the development of new cancer drugs and how precision medicine clinical trial design can help         

close all; clc; clear; tic; %% 01 参数配置 W = 1280; H = 720; save_folder = "data/project"; mkdir(save_folder); save_file_csv = strcat(save_folder, "/","patterns.csv"); % 用于写入到投影仪 n = 4; % 格雷码位数 % 相移参数 N = 12; % 相移步数 A = 130; B = 90; TW = W / (2 ^ n); TH = H / (2 ^ n); %% 02 生成相移法图像 [~, patterns_phaseshift_X] = m_make_phase_shift_patterns(A, B, TW, N, W, H); [~, temp_Y] = m_make_phase_shift_patterns(A, B, TH, N, H, W); patterns_phaseshift_Y = zeros(N, H, W); for i = 1: N patterns_phaseshift_Y(i, :, :) = squeeze(temp_Y(i, :, :))'; end %% 03 生成格雷码图像:X方向 patterns_graycode_X = m_make_gray_code_patterns(n, W, H); temp_Y = m_make_gray_code_patterns(n, H, W); [num, H, W] = size(patterns_graycode_X); patterns_graycode_Y = zeros(num, H, W); for i = 1: num patterns_graycode_Y(i, :, :) = squeeze(temp_Y(i, :, :))'; end %% 04 写入图像 idx = 0; file = fopen(save_file_csv, "w+"); % 写入相移图案 X for i = 1: N idx = idx + 1; % 写入图片 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("写入文件到:" + save_file_img); img = squeeze(patterns_phaseshift_X(i, :, :)); imwrite(img, save_file_img); % 写入csv文件 img_row = squeeze(img(1, :)) * 255.; for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 写入格雷码程序 X for i = 1: num idx = idx + 1; % 写入图像 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("写入文件到:" + save_file_img); img = squeeze(patterns_graycode_X(i, :, :)); imwrite(img, save_file_img); % 写入图像 img_row = squeeze(img(1, :)); for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 写入相移图案 Y for i = 1: N idx = idx + 1; % 写入图片 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("写入文件到:" + save_file_img); img = squeeze(patterns_phaseshift_Y(i, :, :)); imwrite(img, save_file_img); % 写入csv文件 img_row = squeeze(img(1, :)) * 255.; for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 写入格雷码程序 Y for i = 1: num idx = idx + 1; % 写入图像 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("写入文件到:" + save_file_img); img = squeeze(patterns_graycode_Y(i, :, :)); imwrite(img, save_file_img); % 写入图像 img_row = squeeze(img(1, :)); for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ","));close all; clc; clear; tic; %% 01 参数配置 calib_folder = "data/calib"; N = 12; n = 4; num = n + 2; B_min = 10; % 低于这个调制度的我们就认为它的相位信息不可靠 IT = 0.5; % 格雷码阈值 win_size = 7; % 中值滤波窗口大小 W = 1280; H = 720; points_per_row = 7; points_per_col = 6; w = 2; load("data/calib/camera_imagePoints.mat"); [~, ~, calib_num] = size(imagePoints); prjPoints = zeros(size(imagePoints)); %% 02 标定投影仪、相机 for calib_idx = 1: calib_num disp(calib_idx); data_folder = calib_folder + "/" + num2str(calib_idx); %% 02 近似查看图像圆心 img = 255 - imread(data_folder + "/18.bmp"); for i = 1: points_per_row * points_per_col xy = imagePoints(i, :, calib_idx); x = round(xy(1)); y = round(xy(2)); img(y, x) = 255; end figure(); mesh(img); %% 03 解X\Y相位 files_phaseShiftX = cell(1, N); idx = 1; for i = 1: N files_phaseShiftX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeX = cell(1, num); for i = 1: num files_grayCodeX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_phaseShiftY = cell(1, N); for i = 1: N files_phaseShiftY{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeY = cell(1, num); for i = 1: num files_grayCodeY{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end [phaX, difX] = m_calc_absolute_phase(files_phaseShiftX, files_grayCodeX, IT, B_min, win_size); [phaY, difY] = m_calc_absolute_phase(files_phaseShiftY, files_grayCodeY, IT, B_min, win_size); phaX = phaX * W; phaY = phaY * H; for i = 1: points_per_row * points_per_col xy = imagePoints(i, :, calib_idx); x = xy(1); y = xy(2); x_round = round(x); y_round = round(y); % 对x、y附近对相位进行样条曲线插值 xs = zeros(1, 2 * w + 1); ys = zeros(1, 2 * w + 1); phas_x = zeros(1, 2 * w + 1); phas_y = zeros(1, 2 * w + 1); ii = 1; for j = - 1 * w: w es,'X (mm)'); ylabel(player.Axes,'Y (mm)'); zlabel(player.Axes,'Z (mm)'); view(player,ptCloud); pha_y = spline(ys, phas_y, y); prjPoints(i, :, calib_idx) = [pha_x, pha_y]; end end save(calib_folder + "\projector_imagePoints.mat", 'prjPoints'); toc; end fprintf(file, "\n"); end disp("写入完成"); fclose(file); toc;帮我一句一句解释这段代码
09-19
close all; clc; clear; tic; %% 01 鍙傛暟閰嶇疆 W = 1280; H = 720; save_folder = "data/project"; mkdir(save_folder); save_file_csv = strcat(save_folder, "/","patterns.csv"); % 鐢ㄤ簬鍐欏叆鍒版姇褰变华 n = 4; % 鏍奸浄鐮佷綅鏁� % 鐩哥Щ鍙傛暟 N = 12; % 鐩哥Щ姝ユ暟 A = 130; B = 90; TW = W / (2 ^ n); TH = H / (2 ^ n); %% 02 鐢熸垚鐩哥Щ娉曞浘鍍� [~, patterns_phaseshift_X] = m_make_phase_shift_patterns(A, B, TW, N, W, H); [~, temp_Y] = m_make_phase_shift_patterns(A, B, TH, N, H, W); patterns_phaseshift_Y = zeros(N, H, W); for i = 1: N patterns_phaseshift_Y(i, :, :) = squeeze(temp_Y(i, :, :))'; end %% 03 鐢熸垚鏍奸浄鐮佸浘鍍忥細X鏂瑰悜 patterns_graycode_X = m_make_gray_code_patterns(n, W, H); temp_Y = m_make_gray_code_patterns(n, H, W); [num, H, W] = size(patterns_graycode_X); patterns_graycode_Y = zeros(num, H, W); for i = 1: num patterns_graycode_Y(i, :, :) = squeeze(temp_Y(i, :, :))'; end %% 04 鍐欏叆鍥惧儚 idx = 0; file = fopen(save_file_csv, "w+"); % 鍐欏叆鐩哥Щ鍥炬 X for i = 1: N idx = idx + 1; % 鍐欏叆鍥剧墖 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_phaseshift_X(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆csv鏂囦欢 img_row = squeeze(img(1, :)) * 255.; for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 鍐欏叆鏍奸浄鐮佺▼搴� X for i = 1: num idx = idx + 1; % 鍐欏叆鍥惧儚 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_graycode_X(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆鍥惧儚 img_row = squeeze(img(1, :)); for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 鍐欏叆鐩哥Щ鍥炬 Y for i = 1: N idx = idx + 1; % 鍐欏叆鍥剧墖 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_phaseshift_Y(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆csv鏂囦欢 img_row = squeeze(img(1, :)) * 255.; for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 鍐欏叆鏍奸浄鐮佺▼搴� Y for i = 1: num idx = idx + 1; % 鍐欏叆鍥惧儚 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_graycode_Y(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆鍥惧儚 img_row = squeeze(img(1, :)); for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end disp("鍐欏叆瀹屾垚"); fclose(file); toc;close all; clc; clear; tic; %% 01 鍙傛暟閰嶇疆 calib_folder = "data/calib"; N = 12; n = 4; num = n + 2; B_min = 10; % 浣庝簬杩欎釜璋冨埗搴︾殑鎴戜滑灏辫涓哄畠鐨勭浉浣嶄俊鎭笉鍙潬 IT = 0.5; % 鏍奸浄鐮侀槇鍊� win_size = 7; % 涓�兼护娉㈢獥鍙eぇ灏� W = 1280; H = 720; points_per_row = 7; points_per_col = 6; w = 2; load("data/calib/camera_imagePoints.mat"); [~, ~, calib_num] = size(imagePoints); prjPoints = zeros(size(imagePoints)); %% 02 鏍囧畾鎶曞奖浠�佺浉鏈� for calib_idx = 1: calib_num disp(calib_idx); data_folder = calib_folder + "/" + num2str(calib_idx); %% 02 杩戜技鏌ョ湅鍥惧儚鍦嗗績 img = 255 - imread(data_folder + "/18.bmp"); for i = 1: points_per_row * points_per_col xy = imagePoints(i, :, calib_idx); x = round(xy(1)); y = round(xy(2)); img(y, x) = 255; end figure(); mesh(img); %% 03 瑙\Y鐩镐綅 files_phaseShiftX = cell(1, N); idx = 1; for i = 1: N files_phaseShiftX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeX = cell(1, num); for i = 1: num files_grayCodeX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_phaseShiftY = cell(1, N); for i = 1: N files_phaseShiftY{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeY = cell(1, num); for i = 1: num files_grayCodeY{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end [phaX, difX] = m_calc_absolute_phase(files_phaseShiftX, files_grayCodeX, IT, B_min, win_size); [phaY, difY] = m_calc_absolute_phase(files_phaseShiftY, files_grayCodeY, IT, B_min, win_size); phaX = phaX * W; phaY = phaY * H; for i = 1: points_per_row * points_per_col xy = imagePoints(i, :, calib_idx); x = xy(1); y = xy(2); x_round = round(x); y_round = round(y); % 瀵箈銆亂闄勮繎瀵圭浉浣嶈繘琛屾牱鏉℃洸绾挎彃鍊� xs = zeros(1, 2 * w + 1); ys = zeros(1, 2 * w + 1); phas_x = zeros(1, 2 * w + 1); phas_y = zeros(1, 2 * w + 1); ii = 1; for j = - 1 * w: w xs(1, ii) = x_round + j; ys(1, ii) = y_round + j; phas_x(1, ii) = phaX(y_round, xs(1, ii)); phas_y(1, ii) = phaY(ys(1, ii), x_round); ii = ii + 1; end pha_x = spline(xs, phas_x, x); pha_y = spline(ys, phas_y, y); prjPoints(i, :, calib_idx) = [pha_x, pha_y]; end end save(calib_folder + "\projector_imagePoints.mat", 'prjPoints'); toc;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 3D recosntruction with the calibrated triangular stereo model. % Related Reference: % "Calibration of fringe projection profilometry: A comparative review" % Shijie Feng, Chao Zuo, Liang Zhang, Tianyang Tao, Yan Hu, Wei Yin, Jiaming Qian, and Qian Chen % last modified on 07/27/2020 % by Shijie Feng (Email: shijiefeng@njust.edu.cn) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Clear everything existing. clc; clear; close all; data_folder = "data/model"; N = 12; n = 4; num = n + 2; B_min = 10; % 浣庝簬杩欎釜璋冨埗搴︾殑鎴戜滑灏辫涓哄畠鐨勭浉浣嶄俊鎭笉鍙潬 IT = 0.5; % 鏍奸浄鐮侀槇鍊� win_size = 7; % 涓�兼护娉㈢獥鍙eぇ灏� %% step1: input parameters width = 1280; % camera width height = 1024; % camera height prj_width = 1280; % projector width %camera: Projection matrix Pc load('CamCalibResult.mat'); Kc = KK; % 鐩告満鍐呭弬 Ac = Kc * [Rc_1, Tc_1]; %projector: Projection matrix Pp load('PrjCalibResult.mat'); Kp = KK; % 鎶曞奖浠唴鍙� Ap = Kp * [Rc_1, Tc_1]; %% step2: 璇诲彇娴嬭瘯鍥剧墖骞朵笖璁$畻涓夌淮閲嶅缓 % % 鏉$汗棰戠巼64锛屼篃鏄棿璺濓紙涓�涓懆鏈熺敱64涓儚绱犵粍鎴愶級鐢ㄤ簬璁$畻缁濆鐩镐綅锛岄鐜�1銆�8鐢ㄤ簬鍖呰9鐩镐綅灞曞紑 % f = 64; % 鏉$汗棰戠巼锛堝崟涓懆鏈熸潯绾圭殑鍍忕礌涓暟锛夛紝鍗砅 % load('up_test_obj.mat'); % up_test_obj = up_test_obj / f; % 灏嗙浉浣嶅綊涓�鍖栧埌[0, 2pi]涔嬮棿 % % figure; imshow(up_test_obj / (2 * pi)); colorbar; title("鐩镐綅鍥�, freq=" + num2str(f)); % figure; mesh(up_test_obj); colorbar; title("鐩镐綅鍥�, freq=" + num2str(f)); % % % 璁$畻鎶曞奖浠潗鏍� % x_p = up_test_obj / (2 * pi) * prj_width; idx = 1; files_phaseShiftX = cell(1, N); for i = 1: N files_phaseShiftX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeX = cell(1, num); for i = 1: num files_grayCodeX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end [phaX, difX] = m_calc_absolute_phase(files_phaseShiftX, files_grayCodeX, IT, B_min, win_size); up_test_obj = phaX * 2 * pi; x_p = phaX * prj_width; % 3D閲嶅缓 Xws = nan(height, width); Yws = nan(height, width); Zws = nan(height, width); for y = 1:height for x = 1:width if ~(up_test_obj(y, x) == 0) uc = x - 1; vc = y - 1; up = (x_p(y, x) - 1); % Eq. (32) in the reference paper. A = [Ac(1,1) - Ac(3,1) * uc, Ac(1,2) - Ac(3,2) * uc, Ac(1,3) - Ac(3,3) * uc; Ac(2,1) - Ac(3,1) * vc, Ac(2,2) - Ac(3,2) * vc, Ac(2,3) - Ac(3,3) * vc; Ap(1,1) - Ap(3,1) * up, Ap(1,2) - Ap(3,2) * up, Ap(1,3) - Ap(3,3) * up]; b = [Ac(3,4) * uc - Ac(1,4); Ac(3,4) * vc - Ac(2,4); Ap(3,4) * up - Ap(1,4)]; XYZ_w = inv(A) * b; Xws(y, x) = XYZ_w(1); Yws(y, x) = XYZ_w(2); Zws(y, x) = XYZ_w(3); end end end % 鐐逛簯鏄剧ず xyzPoints(:, 1) = Xws(:); xyzPoints(:, 2) = Yws(:); xyzPoints(:, 3) = Zws(:); ptCloud = pointCloud(xyzPoints); xlimits = [min(Xws(:)), max(Xws(:))]; ylimits = [min(Yws(:)), max(Yws(:))]; zlimits = ptCloud.ZLimits; player = pcplayer(xlimits, ylimits, zlimits); xlabel(player.Axes,'X (mm)'); ylabel(player.Axes,'Y (mm)'); zlabel(player.Axes,'Z (mm)'); view(player,ptCloud); 这是代码主体部分,接下来给出功能函数function [pha_absolute, dif] = m_calc_absolute_phase(files_phaseShift, files_grayCode, IT, B_min, win_size) [~, N] = size(files_phaseShift); [pha_wrapped, B] = m_calc_warppred_phase(files_phaseShift, N); [~, n] = size(files_grayCode); n = n - 2; % 鎶曞奖浜嗕竴榛戜竴鐧戒袱骞呭浘鐗� Ks = m_calc_gray_code(files_grayCode, IT, n); pha_absolute = pha_wrapped + 2 * pi .* Ks; % 璋冨埗搴︽护娉� B_mask = B > B_min; pha_absolute = pha_absolute .* B_mask; % 杈圭紭璺冲彉璇樊 [pha_absolute, dif] = m_filter2d(pha_absolute, win_size); % 褰掍竴鍖� pha_absolute = pha_absolute / (2 * pi * 2^ n); endfunction [Ks] = m_calc_gray_code(files, IT, n) % 01 璇诲彇姣忎竴寮犲浘鐗囪繘Is [~, num] = size(files); img = imread(files{1}); [h, w] = size(img); Is = zeros(num, h, w); for i = 1: num img = imread(files{i}); Is(i, :, :) = double(img); end % 02 璁$畻Is_Max銆両s_Min锛屽姣忎釜鐐硅繘琛岄槇鍊煎垽鏂� Is_max = max(Is); Is_min = min(Is); Is_std = (Is - Is_min) ./ (Is_max - Is_min); gcs = Is_std > IT; % 03 瀵规瘡涓儚绱犵偣锛岃绠楃紪鐮佸�糣 Vs_row = zeros(1, 2 ^ n, 'uint8'); codes = m_gray_code(n); for i = 1: 2 ^ n code = str2mat(codes(i)); %#ok<DSTRMT> V = 0; for j = 1: n V = V + str2num(code(j)) * 2^ (4 - j); %#ok<ST2NM> end Vs_row(1, i) = V; end % 04 寤虹珛 V - > K 鐨勬槧灏勮〃 V2K = containers.Map(); for K = 1: 2 ^ n V = Vs_row(1, K); V2K(int2str(V)) = K - 1; end Ks = zeros(h, w); for v = 1: h %disp(strcat("绗�", int2str(v), "琛�")); for u = 1: w % 涓嶉渶瑕佹渶鍚庨粦銆佺櫧涓ゅ箙鍥剧墖鐨勭紪鐮� gc = gcs(1: n, v, u); V = 0; for i = 1: n V = V + gc(i) * 2 ^ (4 - i); end % 涓昏鐨勬�ц兘鐡堕 Ks(v, u) = V2K(int2str(V)); end end end function [Ks] = m_calc_gray_code(files, IT, n) % 01 璇诲彇姣忎竴寮犲浘鐗囪繘Is [~, num] = size(files); img = imread(files{1}); [h, w] = size(img); Is = zeros(num, h, w); for i = 1: num img = imread(files{i}); Is(i, :, :) = double(img); end % 02 璁$畻Is_Max銆両s_Min锛屽姣忎釜鐐硅繘琛岄槇鍊煎垽鏂� Is_max = max(Is); Is_min = min(Is); Is_std = (Is - Is_min) ./ (Is_max - Is_min); gcs = Is_std > IT; % 03 瀵规瘡涓儚绱犵偣锛岃绠楃紪鐮佸�糣 Vs_row = zeros(1, 2 ^ n, 'uint8'); codes = m_gray_code(n); for i = 1: 2 ^ n code = str2mat(codes(i)); %#ok<DSTRMT> V = 0; for j = 1: n V = V + str2num(code(j)) * 2^ (4 - j); %#ok<ST2NM> end Vs_row(1, i) = V; end % 04 寤虹珛 V - > K 鐨勬槧灏勮〃 V2K = containers.Map(); for K = 1: 2 ^ n V = Vs_row(1, K); V2K(int2str(V)) = K - 1; end Ks = zeros(h, w); for v = 1: h %disp(strcat("绗�", int2str(v), "琛�")); for u = 1: w % 涓嶉渶瑕佹渶鍚庨粦銆佺櫧涓ゅ箙鍥剧墖鐨勭紪鐮� gc = gcs(1: n, v, u); V = 0; for i = 1: n V = V + gc(i) * 2 ^ (4 - i); end % 涓昏鐨勬�ц兘鐡堕 Ks(v, u) = V2K(int2str(V)); end end end %% 计算包裹相位 function [pha, B] = m_calc_warppred_phase(files, N) sin_sum = 0; cos_sum = 0; for k = 0: N - 1 Ik = m_imread(files{k + 1}); % 读取图片 Ik = m_filter2d(Ik); sin_sum = sin_sum + Ik * sin(2 * k * pi / N); cos_sum = cos_sum + Ik * cos(2 * k * pi / N); end % 根据计算相位、调制度 pha = atan2(sin_sum, cos_sum); B = sqrt(sin_sum .^ 2 + cos_sum .^ 2) * 2 / N; %% 尝试注释掉这段,自己从零实现一遍 % 为了将波折相位转为单个周期内单调递增 pha = - pha; pha_low_mask = pha <= 0; pha = pha + pha_low_mask .* 2. * pi; end %% 读取图片 function [img] = m_imread(file) img = imread(file); img = double(((img(:, :, 1)))); % 转换灰度图 end %% 高斯滤波 function [img] = m_filter2d(img) w = 3.; sigma = 1.; kernel = fspecial("gaussian", [w, w], sigma); img = imfilter(img, kernel, "replicate"); end% 滤波 function [pha_new, dif] = m_filter2d(pha, win_size) % 中值滤波(格雷码边缘处计算出现问题) pha_new = medfilt2(pha, [win_size, win_size]); % (剔除未编码区域) dif = pha - pha_new; endfunction [code] = m_gray_code(n) if (n < 1) disp("鏍奸浄鐮佹暟閲忓繀椤诲ぇ浜�0"); return; elseif (n == 1) % 浜х敓0銆�1 涓や釜鏁板瓧 code = ["0", "1"]; % 杩斿洖code else code_pre = m_gray_code(n - 1); [~, num] = size(code_pre); % 鍒濆鍖栦竴涓暟缁� code = repmat("", 1, num * 2); % step1锛氭瘡涓瓧绗︿覆鍓嶉潰閮�+0 idx = 0; for i = 1: num idx = idx + 1; code(idx) = "0" + code_pre(i); end % step2锛氱炕杞涓厓绱狅紝鍏朵綑鍙栧绉� for i = num: -1: 1 idx = idx + 1; code(idx) = "1" + code_pre(i); end end endfunction [patterns] = m_make_gray_code_patterns(n, W, H) codes = m_gray_code(n); % 灏嗗瓧绗︿覆鏍奸浄鐮佽浆鎹负鐭╅樀鏍煎紡 [~, num] = size(codes); codes_mat = zeros(n, num, 'int8'); for col = 1: num code_col = str2mat(codes(col)); %#ok<DSTRMT> for row = 1: n codes_mat(row, col) = str2num(code_col(row)); %#ok<ST2NM> end end W_per = round(W / num); % 姣忓紶鍥剧墖 patterns = zeros(n + 2, H, W, "uint8"); for idx = 1: n % 涓�琛屽浘鐗� row_one = zeros(1, W, "uint8"); % 姣忎釜鏍煎瓙 for i = 1 : num gray = codes_mat(idx, i); % 鏍煎瓙閲屾瘡涓儚绱� for w = 1: W_per row_one(1, (i - 1) * W_per + w) = gray; end end row_one = row_one * 255; pattern = repmat(row_one, H, 1); patterns(idx, :, :) = pattern; end % 鍏ㄩ粦銆佸叏鐧藉浘鐗囷紝鐢ㄤ簬纭畾姣忎釜鍍忕礌闃堝�� patterns(n + 2, :, :) = ones(H, W, 'uint8') * 255; end % 函数:生成相移条纹 function [Is, Is_img] = m_make_phase_shift_patterns(A, B, T, N, W, H) Is = cell(N, 1); Is_img = zeros(N, H, W); xs = 1: W; f_2pi = 1. / double(T) * 2. * pi; for k = 0: N - 1 Is{k + 1} = A + B * cos(f_2pi * xs + 2 * k / N * pi); Is_img(k + 1, :, :) = repmat(Is{k + 1} / 255., H, 1); end end 请一句一句的解释代码,我是小白
09-19
帮我一行一行的解读代码function [pha_absolute, dif] = m_calc_absolute_phase(files_phaseShift, files_grayCode, IT, B_min, win_size) [~, N] = size(files_phaseShift); [pha_wrapped, B] = m_calc_warppred_phase(files_phaseShift, N); [~, n] = size(files_grayCode); n = n - 2; % 鎶曞奖浜嗕竴榛戜竴鐧戒袱骞呭浘鐗� Ks = m_calc_gray_code(files_grayCode, IT, n); pha_absolute = pha_wrapped + 2 * pi .* Ks; % 璋冨埗搴︽护娉� B_mask = B > B_min; pha_absolute = pha_absolute .* B_mask; % 杈圭紭璺冲彉璇樊 [pha_absolute, dif] = m_filter2d(pha_absolute, win_size); % 褰掍竴鍖� pha_absolute = pha_absolute / (2 * pi * 2^ n); endfunction [Ks] = m_calc_gray_code(files, IT, n) % 01 璇诲彇姣忎竴寮犲浘鐗囪繘Is [~, num] = size(files); img = imread(files{1}); [h, w] = size(img); Is = zeros(num, h, w); for i = 1: num img = imread(files{i}); Is(i, :, :) = double(img); end % 02 璁$畻Is_Max銆両s_Min锛屽姣忎釜鐐硅繘琛岄槇鍊煎垽鏂� Is_max = max(Is); Is_min = min(Is); Is_std = (Is - Is_min) ./ (Is_max - Is_min); gcs = Is_std > IT; % 03 瀵规瘡涓儚绱犵偣锛岃绠楃紪鐮佸�糣 Vs_row = zeros(1, 2 ^ n, 'uint8'); codes = m_gray_code(n); for i = 1: 2 ^ n code = str2mat(codes(i)); %#ok<DSTRMT> V = 0; for j = 1: n V = V + str2num(code(j)) * 2^ (4 - j); %#ok<ST2NM> end Vs_row(1, i) = V; end % 04 寤虹珛 V - > K 鐨勬槧灏勮〃 V2K = containers.Map(); for K = 1: 2 ^ n V = Vs_row(1, K); V2K(int2str(V)) = K - 1; end Ks = zeros(h, w); for v = 1: h %disp(strcat("绗�", int2str(v), "琛�")); for u = 1: w % 涓嶉渶瑕佹渶鍚庨粦銆佺櫧涓ゅ箙鍥剧墖鐨勭紪鐮� gc = gcs(1: n, v, u); V = 0; for i = 1: n V = V + gc(i) * 2 ^ (4 - i); end % 涓昏鐨勬�ц兘鐡堕 Ks(v, u) = V2K(int2str(V)); end end end %% 计算包裹相位 function [pha, B] = m_calc_warppred_phase(files, N) sin_sum = 0; cos_sum = 0; for k = 0: N - 1 Ik = m_imread(files{k + 1}); % 读取图片 Ik = m_filter2d(Ik); sin_sum = sin_sum + Ik * sin(2 * k * pi / N); cos_sum = cos_sum + Ik * cos(2 * k * pi / N); end % 根据计算相位、调制度 pha = atan2(sin_sum, cos_sum); B = sqrt(sin_sum .^ 2 + cos_sum .^ 2) * 2 / N; %% 尝试注释掉这段,自己从零实现一遍 % 为了将波折相位转为单个周期内单调递增 pha = - pha; pha_low_mask = pha <= 0; pha = pha + pha_low_mask .* 2. * pi; end %% 读取图片 function [img] = m_imread(file) img = imread(file); img = double(((img(:, :, 1)))); % 转换灰度图 end %% 高斯滤波 function [img] = m_filter2d(img) w = 3.; sigma = 1.; kernel = fspecial("gaussian", [w, w], sigma); img = imfilter(img, kernel, "replicate"); end% 滤波 function [pha_new, dif] = m_filter2d(pha, win_size) % 中值滤波(格雷码边缘处计算出现问题) pha_new = medfilt2(pha, [win_size, win_size]); % (剔除未编码区域) dif = pha - pha_new; endfunction [code] = m_gray_code(n) if (n < 1) disp("鏍奸浄鐮佹暟閲忓繀椤诲ぇ浜�0"); return; elseif (n == 1) % 浜х敓0銆�1 涓や釜鏁板瓧 code = ["0", "1"]; % 杩斿洖code else code_pre = m_gray_code(n - 1); [~, num] = size(code_pre); % 鍒濆鍖栦竴涓暟缁� code = repmat("", 1, num * 2); % step1锛氭瘡涓瓧绗︿覆鍓嶉潰閮�+0 idx = 0; for i = 1: num idx = idx + 1; code(idx) = "0" + code_pre(i); end % step2锛氱炕杞涓厓绱狅紝鍏朵綑鍙栧绉� for i = num: -1: 1 idx = idx + 1; code(idx) = "1" + code_pre(i); end end endfunction [patterns] = m_make_gray_code_patterns(n, W, H) codes = m_gray_code(n); % 灏嗗瓧绗︿覆鏍奸浄鐮佽浆鎹负鐭╅樀鏍煎紡 [~, num] = size(codes); codes_mat = zeros(n, num, 'int8'); for col = 1: num code_col = str2mat(codes(col)); %#ok<DSTRMT> for row = 1: n codes_mat(row, col) = str2num(code_col(row)); %#ok<ST2NM> end end W_per = round(W / num); % 姣忓紶鍥剧墖 patterns = zeros(n + 2, H, W, "uint8"); for idx = 1: n % 涓�琛屽浘鐗� row_one = zeros(1, W, "uint8"); % 姣忎釜鏍煎瓙 for i = 1 : num gray = codes_mat(idx, i); % 鏍煎瓙閲屾瘡涓儚绱� for w = 1: W_per row_one(1, (i - 1) * W_per + w) = gray; end end row_one = row_one * 255; pattern = repmat(row_one, H, 1); patterns(idx, :, :) = pattern; end % 鍏ㄩ粦銆佸叏鐧藉浘鐗囷紝鐢ㄤ簬纭畾姣忎釜鍍忕礌闃堝�� patterns(n + 2, :, :) = ones(H, W, 'uint8') * 255; end% 函数:生成相移条纹 function [Is, Is_img] = m_make_phase_shift_patterns(A, B, T, N, W, H) Is = cell(N, 1); Is_img = zeros(N, H, W); xs = 1: W; f_2pi = 1. / double(T) * 2. * pi; for k = 0: N - 1 Is{k + 1} = A + B * cos(f_2pi * xs + 2 * k / N * pi); Is_img(k + 1, :, :) = repmat(Is{k + 1} / 255., H, 1); end end close all; clc; clear; tic; %% 01 鍙傛暟閰嶇疆 W = 1280; H = 720; save_folder = "data/project"; mkdir(save_folder); save_file_csv = strcat(save_folder, "/","patterns.csv"); % 鐢ㄤ簬鍐欏叆鍒版姇褰变华 n = 4; % 鏍奸浄鐮佷綅鏁� % 鐩哥Щ鍙傛暟 N = 12; % 鐩哥Щ姝ユ暟 A = 130; B = 90; TW = W / (2 ^ n); TH = H / (2 ^ n); %% 02 鐢熸垚鐩哥Щ娉曞浘鍍� [~, patterns_phaseshift_X] = m_make_phase_shift_patterns(A, B, TW, N, W, H); [~, temp_Y] = m_make_phase_shift_patterns(A, B, TH, N, H, W); patterns_phaseshift_Y = zeros(N, H, W); for i = 1: N patterns_phaseshift_Y(i, :, :) = squeeze(temp_Y(i, :, :))'; end %% 03 鐢熸垚鏍奸浄鐮佸浘鍍忥細X鏂瑰悜 patterns_graycode_X = m_make_gray_code_patterns(n, W, H); temp_Y = m_make_gray_code_patterns(n, H, W); [num, H, W] = size(patterns_graycode_X); patterns_graycode_Y = zeros(num, H, W); for i = 1: num patterns_graycode_Y(i, :, :) = squeeze(temp_Y(i, :, :))'; end %% 04 鍐欏叆鍥惧儚 idx = 0; file = fopen(save_file_csv, "w+"); % 鍐欏叆鐩哥Щ鍥炬 X for i = 1: N idx = idx + 1; % 鍐欏叆鍥剧墖 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_phaseshift_X(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆csv鏂囦欢 img_row = squeeze(img(1, :)) * 255.; for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 鍐欏叆鏍奸浄鐮佺▼搴� X for i = 1: num idx = idx + 1; % 鍐欏叆鍥惧儚 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_graycode_X(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆鍥惧儚 img_row = squeeze(img(1, :)); for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 鍐欏叆鐩哥Щ鍥炬 Y for i = 1: N idx = idx + 1; % 鍐欏叆鍥剧墖 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_phaseshift_Y(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆csv鏂囦欢 img_row = squeeze(img(1, :)) * 255.; for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end % 鍐欏叆鏍奸浄鐮佺▼搴� Y for i = 1: num idx = idx + 1; % 鍐欏叆鍥惧儚 save_file_img = strcat(save_folder, "/", int2str(idx), ".bmp"); disp("鍐欏叆鏂囦欢鍒�:" + save_file_img); img = squeeze(patterns_graycode_Y(i, :, :)); imwrite(img, save_file_img); % 鍐欏叆鍥惧儚 img_row = squeeze(img(1, :)); for w = 1: W fprintf(file, strcat(int2str(round(img_row(w))), ",")); end fprintf(file, "\n"); end disp("鍐欏叆瀹屾垚"); fclose(file); toc;close all; clc; clear; tic; %% 01 鍙傛暟閰嶇疆 calib_folder = "data/calib"; N = 12; n = 4; num = n + 2; B_min = 10; % 浣庝簬杩欎釜璋冨埗搴︾殑鎴戜滑灏辫涓哄畠鐨勭浉浣嶄俊鎭笉鍙潬 IT = 0.5; % 鏍奸浄鐮侀槇鍊� win_size = 7; % 涓�兼护娉㈢獥鍙eぇ灏� W = 1280; H = 720; points_per_row = 7; points_per_col = 6; w = 2; load("data/calib/camera_imagePoints.mat"); [~, ~, calib_num] = size(imagePoints); prjPoints = zeros(size(imagePoints)); %% 02 鏍囧畾鎶曞奖浠�佺浉鏈� for calib_idx = 1: calib_num disp(calib_idx); data_folder = calib_folder + "/" + num2str(calib_idx); %% 02 杩戜技鏌ョ湅鍥惧儚鍦嗗績 img = 255 - imread(data_folder + "/18.bmp"); for i = 1: points_per_row * points_per_col xy = imagePoints(i, :, calib_idx); x = round(xy(1)); y = round(xy(2)); img(y, x) = 255; end figure(); mesh(img); %% 03 瑙\Y鐩镐綅 files_phaseShiftX = cell(1, N); idx = 1; for i = 1: N files_phaseShiftX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeX = cell(1, num); for i = 1: num files_grayCodeX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_phaseShiftY = cell(1, N); for i = 1: N files_phaseShiftY{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeY = cell(1, num); for i = 1: num files_grayCodeY{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end [phaX, difX] = m_calc_absolute_phase(files_phaseShiftX, files_grayCodeX, IT, B_min, win_size); [phaY, difY] = m_calc_absolute_phase(files_phaseShiftY, files_grayCodeY, IT, B_min, win_size); phaX = phaX * W; phaY = phaY * H; for i = 1: points_per_row * points_per_col xy = imagePoints(i, :, calib_idx); x = xy(1); y = xy(2); x_round = round(x); y_round = round(y); % 瀵箈銆亂闄勮繎瀵圭浉浣嶈繘琛屾牱鏉℃洸绾挎彃鍊� xs = zeros(1, 2 * w + 1); ys = zeros(1, 2 * w + 1); phas_x = zeros(1, 2 * w + 1); phas_y = zeros(1, 2 * w + 1); ii = 1; for j = - 1 * w: w xs(1, ii) = x_round + j; ys(1, ii) = y_round + j; phas_x(1, ii) = phaX(y_round, xs(1, ii)); phas_y(1, ii) = phaY(ys(1, ii), x_round); ii = ii + 1; end pha_x = spline(xs, phas_x, x); pha_y = spline(ys, phas_y, y); prjPoints(i, :, calib_idx) = [pha_x, pha_y]; end end save(calib_folder + "\projector_imagePoints.mat", 'prjPoints'); toc;%% Clear everything existing. clc; clear; close all; data_folder = "data/model"; N = 12; n = 4; num = n + 2; B_min = 10; % 浣庝簬杩欎釜璋冨埗搴︾殑鎴戜滑灏辫涓哄畠鐨勭浉浣嶄俊鎭笉鍙潬 IT = 0.5; % 鏍奸浄鐮侀槇鍊� win_size = 7; % 涓�兼护娉㈢獥鍙eぇ灏� %% step1: input parameters width = 1280; % camera width height = 1024; % camera height prj_width = 1280; % projector width %camera: Projection matrix Pc load('CamCalibResult.mat'); Kc = KK; % 鐩告満鍐呭弬 Ac = Kc * [Rc_1, Tc_1]; %projector: Projection matrix Pp load('PrjCalibResult.mat'); Kp = KK; % 鎶曞奖浠唴鍙� Ap = Kp * [Rc_1, Tc_1]; %% step2: 璇诲彇娴嬭瘯鍥剧墖骞朵笖璁$畻涓夌淮閲嶅缓 % % 鏉$汗棰戠巼64锛屼篃鏄棿璺濓紙涓�涓懆鏈熺敱64涓儚绱犵粍鎴愶級鐢ㄤ簬璁$畻缁濆鐩镐綅锛岄鐜�1銆�8鐢ㄤ簬鍖呰9鐩镐綅灞曞紑 % f = 64; % 鏉$汗棰戠巼锛堝崟涓懆鏈熸潯绾圭殑鍍忕礌涓暟锛夛紝鍗砅 % load('up_test_obj.mat'); % up_test_obj = up_test_obj / f; % 灏嗙浉浣嶅綊涓�鍖栧埌[0, 2pi]涔嬮棿 % % figure; imshow(up_test_obj / (2 * pi)); colorbar; title("鐩镐綅鍥�, freq=" + num2str(f)); % figure; mesh(up_test_obj); colorbar; title("鐩镐綅鍥�, freq=" + num2str(f)); % % % 璁$畻鎶曞奖浠潗鏍� % x_p = up_test_obj / (2 * pi) * prj_width; idx = 1; files_phaseShiftX = cell(1, N); for i = 1: N files_phaseShiftX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end files_grayCodeX = cell(1, num); for i = 1: num files_grayCodeX{i} = strcat(data_folder, "/", int2str(idx), ".bmp"); idx = idx + 1; end [phaX, difX] = m_calc_absolute_phase(files_phaseShiftX, files_grayCodeX, IT, B_min, win_size); up_test_obj = phaX * 2 * pi; x_p = phaX * prj_width; % 3D閲嶅缓 Xws = nan(height, width); Yws = nan(height, width); Zws = nan(height, width); for y = 1:height for x = 1:width if ~(up_test_obj(y, x) == 0) uc = x - 1; vc = y - 1; up = (x_p(y, x) - 1); % Eq. (32) in the reference paper. A = [Ac(1,1) - Ac(3,1) * uc, Ac(1,2) - Ac(3,2) * uc, Ac(1,3) - Ac(3,3) * uc; Ac(2,1) - Ac(3,1) * vc, Ac(2,2) - Ac(3,2) * vc, Ac(2,3) - Ac(3,3) * vc; Ap(1,1) - Ap(3,1) * up, Ap(1,2) - Ap(3,2) * up, Ap(1,3) - Ap(3,3) * up]; b = [Ac(3,4) * uc - Ac(1,4); Ac(3,4) * vc - Ac(2,4); Ap(3,4) * up - Ap(1,4)]; XYZ_w = inv(A) * b; Xws(y, x) = XYZ_w(1); Yws(y, x) = XYZ_w(2); Zws(y, x) = XYZ_w(3); end end end % 鐐逛簯鏄剧ず xyzPoints(:, 1) = Xws(:); xyzPoints(:, 2) = Yws(:); xyzPoints(:, 3) = Zws(:); ptCloud = pointCloud(xyzPoints); xlimits = [min(Xws(:)), max(Xws(:))]; ylimits = [min(Yws(:)), max(Yws(:))]; zlimits = ptCloud.ZLimits; player = pcplayer(xlimits, ylimits, zlimits); xlabel(player.Axes,'X (mm)'); ylabel(player.Axes,'Y (mm)'); zlabel(player.Axes,'Z (mm)'); view(player,ptCloud);
09-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值