Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extracting an image ID from an image path

how can I extract images id from image path.
just want to take 10877 from this path /content/gdrive/MyDrive/new/batch/aligned_10877nationalIdFront.png

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If there is always an underscore before the image ID and if the ID is always 5 digits long try this:

path_name = "/content/gdrive/MyDrive/new/batch/aligned_10877nationalIdFront.png"

image_id = path_name.split("/")[-1].split("_")[1][:5]
print(image_id)

Print out

10877
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading