<div class="qmbox"><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><img src="https://private-user-images.githubusercontent.com/183334968/381782838-2d80b907-8055-4cd9-b749-bfdf1154553f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzA0MzIwNzcsIm5iZiI6MTczMDQzMTc3NywicGF0aCI6Ii8xODMzMzQ5NjgvMzgxNzgyODM4LTJkODBiOTA3LTgwNTUtNGNkOS1iNzQ5LWJmZGYxMTU0NTUzZi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQxMTAxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MTEwMVQwMzI5MzdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kNWZlNmU0ODBkOGEyZTNjZjVhODZjYTc2MWQ4NmIyZDQyNjU2M2ExNDI3NmI2ZDMxMDM2YjAxNGU0OGZjNWE1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.-3Hjx9J1OomzgEkXguOJL05oBNYKHUQ32RmxdmpuIGM"  /><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><span style="color:rgb(31, 35, 40);font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";background-color:rgb(255, 255, 255);display:inline !important">I want to ask how this coefficient is calculated and can the coefficient in the picture be used as a general purpose if I have the airburst data and the projection data</span><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><span style="color:rgb(31, 35, 40);font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";background-color:rgb(255, 255, 255);display:inline !important"><br  /></span></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><img src="cid:366B5C00@EDDFEE43.CA4C246700000000.png" style="max-width: 100%;" image-inside-content="1" fileid="ZF0001_L3zNj8eMlAou5GcAjJ6PQeb" mailid="ZD0001_Hk3Nj8eMlAou5GcACxqcueb"  /><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;">I tried to implement it myself with matlab but I didn't get very good results. Do I need to normalize the input data in the program</div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;">Here is my matlab code I want to implement the fitting coefficient of FSRF But it didn't work out well</div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;">% Using ImageJ for operations:<div>% 1. Extract the last 10 frames of the open exposure, convert to 32-bit, compute the average, draw ROI, measure, and save as an Excel file</div><div>% 2. Extract the stack for the dark field, convert to 32-bit, draw ROI, use multi-measure, and save as an Excel file</div><div>% 3. Split the stack and merge the stack</div><div>% 4. Combine into one Excel file with open exposure data first and dark field data following</div><div>% 5. Copy the mean to a .txt file</div><div>% Result: mean.txt</div><div><br  /></div><div>mean2 = table2array(mean); % Convert imported table type to array type</div><div>m = mean2(1);</div><div>n = mean2(2:end);</div><div>nm = n / m;</div><div><br  /></div><div>% Normalization</div><div>FSRF = nm;</div><div><br  /></div><div>x = 1:510; % Number of dark field frames</div><div>x = x';</div><div>y = FSRF; % Dark field data</div><div><br  /></div><div>% Fitting function</div><div>fitfunc = @(params, x) (params(1) * exp(-params(2) * x) + params(3) * exp(-params(4) * x) + params(5) * exp(-params(6) * x) + params(7) * exp(-params(8) * x));</div><div>initialGuess = [7e-3, 0.001, 1e-2, 0.01, 1e-2, 0.08, 3e-2, 0.6]; % Initial values</div><div><br  /></div><div>paramsFit = lsqcurvefit(fitfunc, initialGuess, x, y);</div><div>B1_fit = paramsFit(1);</div><div>A1_fit = paramsFit(2);</div><div>B2_fit = paramsFit(3);</div><div>A2_fit = paramsFit(4);</div><div>B3_fit = paramsFit(5);</div><div>A3_fit = paramsFit(6);</div><div>B4_fit = paramsFit(7);</div><div>A4_fit = paramsFit(8);</div><div><br  /></div><div>y_fit = fitfunc(paramsFit, x);</div><div>plot(x, y, 'ro', x, y_fit, 'b-');</div><div>grid on</div><div>legend('Sample Data', 'Fitted Curve');</div><div><br  /></div><div>save AB.mat A1_fit A2_fit A3_fit A4_fit B1_fit B2_fit B3_fit B4_fit</div><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;">Here is the program I used to fit the coefficients in matlab into c++</div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;">// TaoSunLagCorrectionTest.cpp : Defines the entry point for the console application.<div>//</div><div><br  /></div><div>#include "stdafx.h"</div><div>#include "TaoSunLagCorrection.h"</div><div>#include "rtkLagCorrectionImageFilter.h"</div><div>#include <chrono> // For timing</div><div>#include <fstream> // For file operations</div><div><br  /></div><div>// Suppress fopen warnings</div><div>#pragma warning(disable:4996)</div><div><br  /></div><div>int main()</div><div>{</div><div>    int height = 1328;</div><div>    int width = 1024;</div><div>    int angles = 360;</div><div><br  /></div><div>    //-------------------- Read projection data ----------------</div><div>    FILE* file1;</div><div>    const char* filename1 = "E:/TaoSunCUDA12/LagCorrection/data/Stack50-409_110kv 15macu 0.5mm 50hz - CT Phantom - full-fan.raw";</div><div><br  /></div><div>    // Buffer to store read data</div><div>    float* proj1 = (float*)malloc(height * width * angles * sizeof(float));</div><div>    if (proj1 == NULL)</div><div>    {</div><div>        printf("Memory allocation failed.\n");</div><div>        return -1;</div><div>    }</div><div><br  /></div><div>    file1 = fopen(filename1, "rb");</div><div>    if (file1 == NULL)</div><div>    {</div><div>        printf("Cannot open file %s\n", filename1);</div><div>        return -1;</div><div>    }</div><div><br  /></div><div>    // Read data from file into memory (vector)</div><div>    printf("Starting to read projection ... \n");</div><div>    fread(proj1, sizeof(float), height * width * angles, file1);</div><div>    fclose(file1);</div><div><br  /></div><div><br  /></div><div>    //--------------------- Correction ----------------------</div><div>    float* projoutput = (float*)malloc(height * width * angles * sizeof(float));</div><div><br  /></div><div>    // Start timing</div><div>    auto start_time = std::chrono::high_resolution_clock::now();</div><div><br  /></div><div>    // Lag correction parameters: detector (inherent characteristics), frame rate (default binning mode)</div><div>    printf("Starting lag correction ... \n");</div><div>    float m_A[4] = { 0.7055f, 0.141f, 0.0212f, 0.0033f };</div><div>    float m_B[4] = { 2.911e-3f, 0.4454e-3f, 0.0748e-3f, 0.0042e-3f };</div><div>    taoSun_LagCorrection(projoutput, proj1, m_A, m_B, height, width, angles);</div><div><br  /></div><div><br  /></div><div>    // End timing</div><div>    auto end_time = std::chrono::high_resolution_clock::now();</div><div><br  /></div><div>    // Output elapsed time</div><div>    std::chrono::duration<double> elapsed = end_time - start_time;</div><div>    std::cout << "Total execution time: " << elapsed.count() << " seconds" << std::endl;</div><div><br  /></div><div>    // After processing all projections, write the large memory data to a file in one go</div><div>    printf("Starting to write corrected projection ... \n");</div><div>    std::ofstream outputFile("E:/TaoSunCUDA12/LagCorrection/data/output0902.raw", std::ios::binary); // Open a new raw file for writing processed data</div><div>    if (!outputFile.is_open())</div><div>    {</div><div>        std::cerr << "Error: Cannot open output raw file!" << std::endl;</div><div>        return EXIT_FAILURE;</div><div>    }</div><div>    size_t totalSize = angles * height * width * sizeof(float);  // Pre-calculate total memory required for all projection data</div><div>    outputFile.write(reinterpret_cast<const char*>(projoutput), totalSize);</div><div>    outputFile.close(); // Close the file  </div><div><br  /></div><div>    // Release the large allocated memory</div><div>    free(projoutput);</div><div>    free(proj1);</div><div><br  /></div><div>    std::cout << "\n\nTest PASSED! " << std::endl;</div><div><br  /></div><div>    return 0;</div><div>}</div><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div style="font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 10.5pt; color: rgb(46, 48, 51); margin-top: 0px; margin-bottom: 0px;"><br  /></div><div xmail-signature=""><xm-signature></xm-signature><p></p></div></div>