tomdoel / pulmonarytoolkit

Lung medical image analysis and visualisation software for Matlab.
GNU General Public License v3.0
84 stars 57 forks source link

some questions about the code #6

Closed charleshm closed 8 years ago

charleshm commented 8 years ago

Hello, Tom Thanks so much for your nice code, it's very clear. I spent a week analyzing it,but sometimes I didn't know why u dealt it in that way(I can understand your code, but I don't know why..).

Could u give me a list of paper that you refer to ? I'll keep focusing on your work.

PeterMcGor commented 8 years ago

Hi Tom;

I just found your code, I want to try it with some images. I had a small problem trying to lunch the GUI. I got this error:

92 if (7 == exist(binDir, 'dir')) && ~strcmp(currentLibPath(1:length(binDir) + 1), [binDir ':']) Index exceeds matrix dimensions.

Error in DepMat.fixCurlPath (line 92) if (7 == exist(binDir, 'dir')) && ~strcmp(currentLibPath(1:length(binDir) + 1), [binDir ':'])

Error in DepMat (line 26) DepMat.fixCurlPath;

Error in PTKUpdate (line 22) depMat = DepMat(repoList, rootSourceDir);

Error in ptk (line 19) updated = PTKUpdate;

if you go to the DepMat.fixCurlPath (line 92)

 function fixCurlPath
            % Matlab's curl configuration doesn't include https so git will not work.
            % We need to add the system curl configuration directory earlier in the
            % path so that it picks up this one instead of Matlab's
            currentLibPath = getenv('DYLD_LIBRARY_PATH');
            binDir = '/usr/lib';
            if (7 == exist(binDir, 'dir')) && ~strcmp(currentLibPath(1:length(binDir) + 1), [binDir ':'])
                setenv('DYLD_LIBRARY_PATH', [binDir ':' currentLibPath]);
            end
        end

The point is DYLD_LIBRARY_PATH is just for MAC so in my case (Linux) I have changed to LD_LIBRARY_PATH and its works!!, I have not tried but the documentation says is PATH for Windows.

Best Regards and congrats for the toolkit!

tomdoel commented 8 years ago

Hi @PeterMcGor ,

Thanks for your fix! I appreciate your time and I will add a fix to the codebase. I haven't run this software recently on Linux so I'm aware there may be some problems.

tomdoel commented 8 years ago

Hi @Hackeme Thanks for your comments. Here are some of the papers describing methods used by the code (other papers are currently in publication):

Lobe segmentation: Doel, T.; Matin, T.N.; Gleeson, F.V.; Gavaghan, D.J.; Grau, V., Pulmonary lobe segmentation from CT images using fissureness, airways, vessels and multilevel B-splines. Biomedical Imaging (ISBI), 2012 9th IEEE International Symposium on , vol., no., pp.1491-1494, 2-5 May 2012. doi: 10.1109/ISBI.2012.6235854

Airway, lung and lobe analysis: KS Burrowes‚ T Doel‚ M Kim‚ C Vargas‚ J Roca‚ V Grau and D Kay: A combined image-modelling approach assessing the impact of hyperinflation due to emphysema on regional ventilation–perfusion matching. Computer Methods in Biomechanics and Biomedical Engineering: Imaging & Visualization 04/2015; DOI: 10.1080/21681163.2015.1023358

Burrowes KS, Doel T, Brightling C. Computational modeling of the obstructive lung diseases asthma and COPD. Journal of Translational Medicine. 2014;12(Suppl 2):S5. doi:10.1186/1479-5876-12-S2-S5.

Registration: Cahill, N.D., Noble, J.A., Hawkes, D.J., Ray, L.A.: Fast fluid registration with Dirichlet boundary conditions: a transform-based approach. IEEE International Symposium on Biomedical Imaging, 712-715 (2007).

Vesselness: Frangi, A., Niessen, W.J., Vincken, K., Viergever, M.A.: Multiscale vessel enhancement filtering. Medical Image Computing and Computer-Assisted Intervention 1496, 130-137 (1998).

Watershed algorithm: Vincent, L., Soille, P.: Watersheds in digital spaces: an efficient algorithm based on immersion simulations. IEEE Transactions on Pattern Analysis and Machine Intelligence 13(6), 583-598 (1991).

Multilevel B-splines: S. Lee, G. Wolberg, and S. Y. Shin. Scattered data interpolation with multilevel B-splines. IEEE Transactions on Visualization and Computer Graphics, 3(3):229--244, 1997.

imagereg commented 8 years ago

Dear Tom,

I just cloned the pulmonary toolkit directory. I was getting the same error with DYLD_LIBRARY_PATH as mentioned here before but I changed to LD_LIBRARY_PATH as I am using Linux. I think you should fix this error on github as there will be many linux users wanting to use your code.

However, when I run ptk, I get the following errors:

WARNING: No cache file found. Will create new one on exit WARNING: No image database file found. Will create new one on exit PTKFastEigenvalues requires compilation. Building with 'g++'. Error using mex cc1plus: error: unrecognized command line option "-std=c++11"

Error in PTKCompileMexFiles>Compile (line 137) mex_result = mex(mex_arguments{:});

Error in PTKCompileMexFiles (line 42) Compile(mex_files_to_compile, cached_mex_file_info, output_directory, compiler, force_recompile, reporting);

Error in PTKFrameworkSingleton (line 105) PTKCompileMexFiles(obj.FrameworkCache, false, reporting);

Error in PTKFrameworkSingleton.GetFrameworkSingleton (line 39) FrameworkSingleton = PTKFrameworkSingleton(reporting);

Error in PTKMain (line 63) obj.FrameworkSingleton = PTKFrameworkSingleton.GetFrameworkSingleton(obj.Reporting);

Error in PTKGuiDataset (line 39) obj.Ptk = PTKMain(reporting);

Error in PTKGui (line 88) obj.GuiDataset = PTKGuiDataset(obj, obj.ImagePanel, obj.GuiSingleton.GetSettings, obj.Reporting);

Error in ptk (line 35) PTKGui(splash_screen);

Do you have any idea how I can solve this?

tomdoel commented 8 years ago

Hi @imagereg, it looks like you need to update your g++ compiler to a newer version. Matlab officially supports g++ 4.7 and above. Versions 4.6 and earlier don't support the -std=c++11 flag which is why you're getting this error (this flag is set by Matlab, not by PTK). You can use !g++ --version to check which version you're using.

For g++ versions 4.3 through 4.6 it might be possible to make them work by modifying your mex options (something like ~/.matlab/R2015b/mex_C++_glnxa64.xml - change the location to match your Matlab and OS) and changing -std=c++11 to -std=c++01. But I'd recommend updating g++.

Here's an example of someone with basically the same problem.

imagereg commented 8 years ago

Thanks Tom,

That works now. How long does it approximately take to run to segment the lobes?

I have been running it for more than an hour but it still is running? Is this normal? I have around 120 slices.

Also some proprietary software such as VIDA offer guidelines on specifications of the Ct data such as 0.5 to 1.5mm slice thickness. For the data set I am testing, I have 2.5mm slice thickness. Is this too low to segment the lobes?

tomdoel commented 8 years ago

@imagereg normally 5-10 mins to segment the lobes from scratch. Are you sure it hasn't stopped at an error?

Another possibility is that if there were problems compiling the mex files, it may fall back on very slow Matlab functions. You can force recompilation of the mex files as follows: ptk_main = PTKMain; pt_main.Recompile; and make sure there are no compilation errors.

The lobe segmentation doesn't always work at 2.5mm - for example it may fail because it can't segment enough of the airway tree. Lung segmentation should normally work, lobe segmentation may or may not work, and you might not get the middle right lobe.

imagereg commented 8 years ago

Hi Toem,

I have updated my gcc to version 5.2.

Similarly I recompiled the mex files. However, I still have not been able to perform a lobar segmentation (although the right and left lung segmentations when the specific option is clicked, works very well). I get the following error:

The plugin PTKLobes failed with the following error: Invalid MEX-file '/data/pulmonarytoolkit/bin/mba_surface_interpolation.mexa64': /usr/local/packages6/matlab/R2015a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /data/pulmonarytoolkit/bin/mba_surface_interpolation.mexa64)

Any ideas how to fix this?

tomdoel commented 8 years ago

It looks like when Matlab compiles the file, it is linking against the wrong version of the standard library (libstdc++). The standard library has to match the compiler. Your gcc 5.2 compiler will have a compatible version of libstdc++ included, and normally your paths would be set up so that it is found and used. However, Matlab also bundled with it another version of the libstdc++ which is not compatible with your compiler. That doesn't matter as long as the correct one is used by the compiler. The problem is that Matlab's mex function is automatically inserting its own standard library path into the linking path, so that the incompatible library is found before the compatible one (this is the /usr/local/packages6/matlab/R2015a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6 in your error message).

Here is a SO question which is basically describing the same problem with some possible solutions: https://stackoverflow.com/questions/9959306/how-to-tell-mex-to-link-with-the-libstdc-so-6-in-usr-lib-instead-of-the-one-i

I would first look at editing the .matlab7rc.sh script and modifying the LDPATH_PREFIX to point to your gcc library path. I would also delete the mex file each time you try to compile, just to make sure it does recompile each time.

ehsanabadi commented 8 years ago

Hi Toem, Thanks for your great toolkit. I have a problem using some of the plugins in the GUI. This is the error: "The plugin "....." failed with the following error: Index exceeds matrix dimensions" Would you please help me to fix this?

tomdoel commented 8 years ago

Hi Ehsan Could you post the error output into a a new issue (as I'm going to close this one) so I can try and diagnose the problem? Unfortunately, some plugins don't always work on all types of data, as the code is still very experimental- e.g. lobes and segments might not work if the slice thickness is large or the image is noisy. I might not be able to resolve the issue but I can at least provide a more helpful error message. Thanks! Tom

ehsanabadi commented 8 years ago

Thanks Tom for your response. You are right. I changed the data and now other plugins are working. So, as you said, it seems that some plugins do not work on some types of data. As I am very fascinated with your toolkit, I have two more questions: 1) What is you strategy for the volume filling part? Are you inspired by Tawhai's paper for VFB?

Tawhai, M. Howatson, A. J. Pullan, and P. J. Hunter. "Generation of an anatomically based three-dimensional model of the conducting airways." Annals of biomedical engineering 28.7 (2000): 793-802.

if yes, are you taking care of the intersections? Because I used your airway growing. Then, I used the StartPoint and EndPoint and by assigning the Horsfield diameter, I experience intersection in some of the branches.

2) Is it possible to export StartPoints and EndPoints of the vessels as you put in the airway centerline plugin?

Thanks, Ehsan

tomdoel commented 8 years ago

Hi Ehsan,

1) Yes, the algorithm is partly inspired by the Tawhai wt al. 2004 algorithm and in fact if you look at Library/Airways/PTKAirwayGenerator.m you'll see that I have mentioned this in the header. Raf Bordas wrote a C++ implementation of the Tawhai wt al. 2004 paper, but had to make some modifications because the algorithm as described in the paper doesn't quite work. My Matlab implementation is derived from his code, but I have also made a number of additional modifications to make it more efficient in Matlab, which are (mostly) documented in this file. Since I have already segmented the lobes and the lobar bronchi, I grow the airways into each lobe. I also resample the lung mask to the grid of points used for the growing, which provides a quick way of detecting whether airways are inside or outside the lung boundary.

NB since the growing depends on the lobar segmentation, if the automatic lobar segmentation does not produce a good result then it can be corrected with the Toolkit's interactive correction tool - then re-running the airway growing will make it run again using the corrected lobes.

The endpoints of the airways will be at distinct points but the airways themselves could intersect, as is the case I believe with Tawhai 2004. That may or may not be a problem depending on your application of the grown airways!

2) I don't think this is possible in the toolkit at the moment since the vessels are detected only using a filter - there is no processing to find the start and end points. You would have to feed the vessel segments into a skeletonisation or a vessel growing algorithm to turn them into a vessel tree. I imagine some work has been done on this (e.g. see the Vessel 09 challenge)

ehsanabadi commented 8 years ago

Thanks Tom for your time and your detailed response.

tomdoel commented 8 years ago

Hi @ehsanabadi. I recently found a bug in the code which could be one cause of the error you previous saw (The plugin "....." failed with the following error: Index exceeds matrix dimensions"). This should be fixed in the newest version (1.6).

tomdoel commented 8 years ago

Closing as the issues in this thread are fixed in the latest version (0.6)