Open Y7NINE opened 4 days ago
@Y7NINE parameters.cpp file may not be compiled at your project.
@hws203 Okay, teacher. I tried recompiling, but I still encountered these issues. Below is my C++ code. If possible, could you generate it in your project? I want to understand whether the issue is with my usage or the environment.
int main() { // Initialize parameters object parameters params;
// Set relevant parameters (e.g., geometry, GPU usage, etc.)
params.geometry = parameters::CONE;
params.helicalPitch = 0.0;
params.whichGPU = -1; // -1 means using CPU, set to 0 or positive integer to use GPU
// Initialize projection data (g) and result array (f)
int numAngles = 180; // Number of angles
int numRows = 512; // Number of rows in the projection data
int numCols = 512; // Number of columns in the projection data
float* g = (float*)malloc(sizeof(float) * numAngles * numRows * numCols);
float* f = (float*)malloc(sizeof(float) * params.numX * params.numY * params.numZ); // Reconstructed volume data
// Fill in the projection data for g (assume you have data available)
// For example: load projection data from a file or generate it
// Create filteredBackprojection object
filteredBackprojection fbp;
// Execute the FBP algorithm
bool result = fbp.execute(g, f, ¶ms, true); // true indicates data is on the CPU
if (result) {
printf("FBP execution succeeded!\n");
} else {
printf("FBP execution failed!\n");
}
// Free allocated memory
free(g);
free(f);
return 0;
}
It is not related to your main code, that is a environment issue. So you need to check whether your project environment include the parameters.cpp file.
@hws203 Haha, thanks for the heads-up! Looks like I need to debug my environment as much as my code. Guess my parameters need more attention than my actual code!
@hws203 I apologize for bothering you again. I've become quite fascinated with this program recently, and I've run into some issues. I'm currently trying to implement the Python version of the FBP program in C++. I'm seeking help with a humble and eager-to-learn attitude. This is my python program I saw the initialization parameters in parameters.cpp so I tried to set the same parameters as the ones called in python In C++, I also refer to the way of another author to put the projection data into the three-dimensional way However, there is still an endless loop in the fft but instead of reporting an error, the cpu keeps showing full Below is my c++ code. I suspect that my input method is not quite right. Can you give me some suggestions
---------------------------I'm really sorry to bother you by asking questions these days-------------------------
int main() { // Initialize projection data (g) and result array (f) int numAngles = 800; // Number of angles int numRows = 1024; // Number of rows in the projection data int numCols = 1328; // Number of columns in the projection data float pixelSize = 0.3; float na = numAngles; float betas_rad = (float)malloc(sizeof(float) na); //投影角度内存 for (int idx = 0; idx < na; idx++) { betas_rad[idx] = float(-idx) / float(na) 360.f; // 计算角度 } // Initialize parameters object parameters params;
// Set relevant parameters (e.g., geometry, GPU usage, etc.)
params.geometry = parameters::CONE;
params.helicalPitch = 0.0;
params.whichGPU = -1; // -1 means using CPU, set to 0 or positive integer to use GPU
params.numX = 1024;
params.numY = 1024;
params.numZ = 400;
params.sod = 566.52;
params.sdd = 1009.04;
params.pixelWidth = 0.3;
params.pixelHeight = 0.3;
float xh_offset = 178.97;
params.centerCol = 0.5 * (numCols - 1) - xh_offset / pixelSize;
params.centerRow = 0.5 * (numRows - 1);
params.voxelHeight = 0.371;
params.voxelWidth = 0.3525;
params.numAngles = 800;
params.angularRange = 360;
params.phis = betas_rad;
params.numRows = 1024; // Number of rows in the projection data
params.numCols = 1328;
params.offsetScan = true;
params.truncatedScan = true;
float* g = (float*)malloc(sizeof(float) * numAngles * numRows * numCols);//物体投影数据
float* f = (float*)malloc(sizeof(float) * params.numX * params.numY * params.numZ); // Reconstructed volume data
//++++++++++++object projection+++++++++++++
FILE* fid = NULL;
printf("Start to read object projection!\n");
const char* proj_file_1 = { "proj-42-841.raw" };
fid = fopen(proj_file_1, "rb");
if (fid == NULL) { printf("\nERROR: Could not open pre-weight file %s\n", proj_file_1); }
fread(g, sizeof(float), numAngles * numRows * numCols, fid);
fclose(fid);
printf("Reading object projection is done!\n");
// Fill in the projection data for g (assume you have data available)
// For example: load projection data from a file or generate it
// Create filteredBackprojection object
filteredBackprojection fbp;
// Execute the FBP algorithm
bool result = fbp.execute(g, f, ¶ms, true); // true indicates data is on the CPU
//bool result = fbp.execute(g, f, &*params, false);
if (result) {
printf("FBP execution succeeded!\n");
}
else {
printf("FBP execution failed!\n");
}
const char* fname_out = "Half-fanFDK-.raw";
printf("Writing output image to file....\n");
fid = fopen(fname_out, "wb");
fwrite(f, sizeof(float), 1024 * 1024 *400, fid);
fclose(fid);
printf("DONE!!\n");
// Free allocated memory
free(g);
free(f);
return 0;
}
Hello. At first glance, everything looks correct. The CPU routines in LEAP have fell behind and are not supported well at this point. The CPU-based filtering is especially slow, so maybe start with a small test case to see if things are working properly. For example, just use one detector row. Do you not have access to a GPU?
And one more suggestion. I highly recommend that you only use the API through the tomographicModels class if you are using the C++ API. The other classes were not designed to be used.
@kylechampley Thank you very much for your advice but there are still some problems copying the python order to call the c++ program past but the result is non-zero. I verified that my input and parameters are the same as in the python program. Is there a problem with my c++ api use The two True parameters in the python program I modified in parameters.cpp The result is zero Is there a problem with how I call it I can use the GPU you said, but I have not figured out how to pass the parameters of cuda, will the following error appear
int main() { // Initialize projection data (g) and result array (f) int numAngles = 800; // Number of angles int numRows = 1024; // Number of rows in the projection data int numCols = 1328; // Number of columns in the projection data float pixelWidth = 0.3; float pixelHeight = 0.3; int numX = 1024; int numY = 1024; int numZ = 400; float xh_offset = 178.97; float centerCol = 0.5 (numCols - 1) - xh_offset / pixelWidth; float centerRow = 0.5 (numRows - 1); float sod = 566.52; float sdd = 1009.04; float voxelHeight = 0.3525; float voxelWidth = 0.371; float offsetX = 0.0; float offsetY = 0.0; float offsetZ = 0.0;
float* phis = (float*)malloc(sizeof(float) * numAngles);
for (int idx = 0; idx < numAngles; idx++)
{
phis[idx] = float(-idx) / float(numAngles) * 360.f;
}
float* g = (float*)malloc(sizeof(float) * numAngles * numRows * numCols);
float* f = (float*)malloc(sizeof(float) * numX * numY * numZ); // Reconstructed volume data
//++++++++++++object projection+++++++++++++
FILE* fid = NULL;
printf("Start to read object projection!\n");
const char* proj_file_1 = { "proj-42-841.raw" };
fid = fopen(proj_file_1, "rb");
if (fid == NULL) { printf("\nERROR: Could not open pre-weight file %s\n", proj_file_1); }
fread(g, sizeof(float), numAngles * numRows * numCols, fid);
fclose(fid);
printf("Reading object projection is done!\n");
// Create tomographicModels object
tomographicModels fbp;
// Execute the FBP algorithm
bool set_conebeam = fbp.set_conebeam(numAngles, numRows, numCols, pixelHeight, pixelWidth, centerRow, centerCol, phis, sod, sdd);
bool set_volume = fbp.set_volume(numX, numY, numZ, voxelWidth, voxelHeight, offsetX, offsetY, offsetZ);
bool parameters = fbp.print_parameters();
bool fdk = fbp.FBP_cpu(g,f);
if (fdk) {
printf("FBP execution succeeded!\n");
}
else {
printf("FBP execution failed!\n");
}
const char* fname_out = "Half-fanFBP-.raw";
printf("Writing output image to file....\n");
fid = fopen(fname_out, "wb");
fwrite(f, sizeof(float), numX * numY * numZ, fid);
fclose(fid);
printf("DONE!!\n");
// Free allocated memory
free(g);
free(f);
return 0;
}
It's hard to diagnose the issue because I only have partial information here. Anyway, one issue I see here is that you are using FBP_cup and FBP_gpu. These functions are deprecated and are only there for backward compatibility. Just use the FBP function in the tomographicModels class and hand it data on the CPU. It will handle all the CPU-to-GPU data transfers for you and there should be nothing you need to do.
Also, I don't recommend changing the defaults in parameters.cpp. If you want to change these variables just do this:
tomographicModels leapct;
leapct.params.set_offsetScan(true);
leapct.params.set_truncatedScan(true);
@kylechampley Thank you so much for my confusion about Just use the FBP function in the tomographicModels class
I tried all the FPB functions in the class and the results were all zeros but my python program was able to reconstruct the image I uploaded my data and my programs in a zip pack https://drive.google.com/file/d/1McaHp96NDRYJvrKwkP-lw-Q42X0zH8GY/view?usp=sharing
In python I put air in it but the c++ program still runs with all zeros The C++ call function can run through but the result is always 0 there is an input
import numpy as np from leap_preprocessing_algorithms import * from leapctype import tomographicModels leapct = tomographicModels() import tifffile as tiff
numAngles = 800 numRows = 1024 numCols = 1328 pixelSize = 0.3 xh_offset = 178.97 centerCol = 0.5 * (numCols - 1) - xh_offset / pixelSize sod = 566.52 sdd = 1009.04
na = numAngles betas_rad = np.zeros(na, dtype=np.float32) # Example of a radians array
for idx in range(na): betas_rad[idx] = -float(idx) / float(na) 2.0 np.pi # Calculating radians
angles = np.degrees(betas_rad)
leapct.set_conebeam(numAngles, numRows, numCols, pixelSize, pixelSize, 0.5 * (numRows - 1), centerCol, angles, sod, sdd) leapct.set_offsetScan(True) leapct.set_truncatedScan(True) leapct.set_volume(1024, 1024, 400, 0.371, 0.3525, 0, 0, 0) leapct.print_parameters()
g = tiff.imread(r'E:\LEAP-1.23\LEAP-1.23\myFDK\proj-42-841.tif')
air = tiff.imread(r'E:\LEAP-1.23\LEAP-1.23\myFDK\air.tif')
ROI = [30, 80, 950, 1000] makeAttenuationRadiographs(leapct, g, air, None, ROI)
vol = leapct.allocateVolume(0) leapct.FBP(g, vol) leapct.display(vol)
raw_file_path = './proj_1014.raw' vol.tofile(raw_file_path) print(f"The reconstruction result has been saved as {raw_file_path}")
The initial suspicion is that my argument did not pass in or did not call the function successfully. I am trying to modify it. Do you have a better idea
Hello, when I try to generate the win_build configuration VS environment call function, there are always the following warnings. Is there any good solution? (This problem may be some brainless. I am a beginner who is interested in computers.