Ask Your Question

Revision history [back]

My program takes partial filenames

I have a code and when I run it for all the images in a folder, it takes the partial file names.

if __name__ == "__main__":
data_catalog = "data"
raw_catalog = "raw_vessels"
vessel_catalog = "vessels_images"
files_names = [x for x in os.listdir(data_catalog) if os.path.isfile(os.path.join(data_catalog,x))]
#files_names.sort()

for file_name in files_names:
    out_name = file_name.split('.')[0]
    org_image = cv2.imread(data_catalog + '/' + file_name)
    raw_vessel, vessel_image = detect_vessel(org_image)
    cv2.imwrite(raw_catalog + '/' + out_name + ".JPG", raw_vessel)
    cv2.imwrite(vessel_catalog + '/' + out_name + ".JPG", vessel_image)

I am skipping description of "detect_vessel" part here. When I run this code, the output file in raw_vessel and vessel_image folder is seems to have a partial name compared to original filename. For example- the original file name is "moderate_1-20100106_152702_172.23.132.69_P09_CLIP_S_30921_36650_DES.mpg-0047.bmp" and the output is raw_vessel and vessel_image folder is "moderate_1-20100106_152702_172.JPG".

I cant figure out the problem. I have a lot images that start with same name with last part of images varrying. Please help me out.