0

I am trying to implement code written to pre-process brain images that contain bleeds to later on train YOLOv4 to identify these bleeds. The code does run correctly on the author's device, but when I try to run it on my local machine, I get the error pasted below.

Code snippet on which I get the errors:

def text_file_writer(file_path, data):
    base_path = 'C:\\UCL_CMB_Project\\Bleed_Images'
    file_to_write = os.path.join(base_path, file_path.split('/')[-1][:7])

    for i in data:
        i = [str(j) for j in i]
        filename = file_to_write + '_Slice' + str(i[-1]) + '.txt'
        file = open(filename, 'w')
        file.write(' '.join(i[:-1]))
        file.close()


def controller_function(file_path):
    # Get paths to all of the masked images
    all_files = get_mask_images(file_path)

    for file in all_files:
        logging.info('Processing file: {}'.format(file))
        path_to_file, locations, locations_non = get_positions(file)

        if len(locations_non) == 0:
            print('No CMBs detected for path: {}'.format(path_to_file))
        else:
            text_file_data = prepare_centres(path_to_file, locations)
            text_file_writer(path_to_file, text_file_data)
            open_actual_image(file, locations_non, add_red_pixel=False)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    logging.info('Main program Starting')
    path_to_folders = 'C:\\UCL_CMB_Project\\Positive_Samples_Only'
    controller_function(path_to_folders) 

Error:

C:\UCL_CMB_Project\venv\Scripts\python.exe C:/UCL_CMB_Project/Image_preprocessing.py
INFO:root:Main program Starting
INFO:root:Processing file: C:\UCL_CMB_Project\Positive_Samples_Only\1004914_20251_2_0\SWI\Segmentation\1004914_Segmented_mask.nii.gz
Traceback (most recent call last):
 File "C:/UCL_CMB_Project/Image_preprocessing.py", line 146, in <module>
   controller_function(path_to_folders)
 File "C:/UCL_CMB_Project/Image_preprocessing.py", line 138, in controller_function
   text_file_writer(path_to_file, text_file_data)
 File "C:/UCL_CMB_Project/Image_preprocessing.py", line 121, in text_file_writer
   file = open(filename, 'w')
PermissionError: [Errno 13] Permission denied: 'C:\\UCL__Slice26.txt'

I don't even understand these errors very well, could anyone shed some light?enter image description here

4

0 回答 0