btcrabb / CAP-Automated-Pipeline

Fully-automated, deep-learning based pipeline to generate biventricular cardiac models from raw cine SSFP MRI images.
MIT License
0 stars 0 forks source link

Cannot processing guide points sometimes #8

Closed MalikTeng closed 1 year ago

MalikTeng commented 2 years ago

Describe the bug Some times when after I manually correct the landmark points on 3CH view the notebook cannot process the guide points and throw errors below,

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [131], in <cell line: 15>()
      6 output_folder = "/mnt/DATA/Experiment/UCSD/processed/" + patient
      8 GuidePoints = GuidePointProcessing(patient,
      9                                   image_folder,
     10                                   segment_folder,
     11                                   output_folder,
     12                                   slice_info_df,
     13                                   landmarks_df)
---> 15 GuidePoints.extract_guidepoints(display = False)

File ~/Documents/UCSD/src/guidepointprocessing.py:788, in GuidePointProcessing.extract_guidepoints(self, display)
    786 self.get_segmentation_files()
    787 self.process_short_axis(display=display)
--> 788 self.process_long_axis(display=display)
    789 self.process_landmarks()

File ~/Documents/UCSD/src/guidepointprocessing.py:574, in GuidePointProcessing.process_long_axis(self, display)
    570         RV_septal_pts = remove_valve_points(RV_septal_pts, [tv1, tv2])           
    572 if view == '3CH':
    573     # mitral valve
--> 574     mv1 = landmarks['MV1'].item()
    575     mv2 = landmarks['MV2'].item()
    577     if np.isnan(mv1).any() or np.isnan(mv2).any():

File ~/anaconda3/envs/CAP/lib/python3.8/site-packages/pandas/core/base.py:349, in IndexOpsMixin.item(self)
    347 if len(self) == 1:
    348     return next(iter(self))
--> 349 raise ValueError("can only convert an array of size 1 to a Python scalar")

ValueError: can only convert an array of size 1 to a Python scalar

I print out the landmarks['MV1'] and there is no points recorded in landmarks['MV1'], Series([], Name: MV1, dtype: object)

But those points should be recorded because I saw the output like this when printing out the 'three_chamber_df', Screenshot from 2022-08-05 15-49-41

MalikTeng commented 2 years ago

A quick update -- When I try to visualize the GP_ED.txt for Venus 2, the notebook print out the following, Screenshot from 2022-08-05 16-28-16

But when I set the parameter 'display' for GuidePoints.extract_guidepoints() as True, it displays all the landmark points and guide points. So those points are actually been generated but weren't recorded to the GP_ED.txt file.

MalikTeng commented 2 years ago

This issue happens when I change the ED phase from 0 to another, e.g. 36. In that case, if the cine images don't have that many phases, e.g. only 20, the volume at that phase will be all zero and the notebook won't find any landmark points from the volume. This is quite common for manual labelling that choosing a phase as ED for SAX images while another phase for LAX images.

Consequentially, I stick to using your phase prediction network to decide the ED and ES frames instead of using the manually selected phases.

btcrabb commented 2 years ago

Just to clarify, the issue is that the ED points are not written to the guide points file? However, they still display correctly? Let me look into this a little since this is an issue that should be resolved.

btcrabb commented 2 years ago

I found the problem in the guidepointprocessing.py file, lines 279 - 282 for the SAX view (also in other locations for the LAX views, this occurs every place the write_to_GP_file() command is used).

ED is hard coded as 0 in this file (i.e., it will only recognize it ad ED if time is < 1). All other points are written to the ES file. Should be a simple fix.