Forum

Author Topic: Change images names after Align photos  (Read 20386 times)

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Change images names after Align photos
« on: May 21, 2016, 10:11:23 PM »
Hi,

i work on a big project underwater from 2014 so from 2015 until now i used to rename my images before i process them (just in case to change path for example or directory) but unfortunately when i start work at 2014 i didn't rename the images (17k images)  so that lead to all the images interfere on each other on Photos pane (i.e two images in two different days have the same name become beside each other in Photos Pane). so my question:
 is there a possibility to rename the images after i made the align step without reprocess the images again? or script to do that Automatically .

Thanks,,
 

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Change images names after Align photos
« Reply #1 on: May 23, 2016, 11:23:52 AM »
Hello tornado2011,

Do you wish to rename the images themselves or just the camera labels, how they are displayed in PhotoScan project window? And how they should be renamed?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #2 on: May 25, 2016, 02:37:41 PM »
Hi Alexey ,

Thank you for your message!

Yes i want to change  camera label after i made Align photos in photoscan without reprocess them again.
The images names was the camera Default names (ex. DSC_0001) and after month i go again to the site and shoot again with the same names i notice this mistake later, So i usually rename my images as follow ( Day of Diving_Name of Diver_Photogram_Name of image)!
a snap shot will show you what i mean! BTW i know how to change images names but i want to change camera labels in PhotoScan after i Align photos with old names, without Align them again.

Thank you,,
Mohammed
« Last Edit: May 25, 2016, 06:26:21 PM by tornado2011 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Change images names after Align photos
« Reply #3 on: May 26, 2016, 04:56:18 PM »
Hello Mohammed,

I understand the task, but the question is how do you wish to rename them? Automatically, based on the path or some metadata, or for selected groups of cameras in the Photos pane, but inputting the prefix to the string input dialog, for example?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #4 on: May 26, 2016, 05:59:13 PM »
Dear Alexey,
 
Thank you for your message!
Yes i want to rename camera labels automatically based on the path (if with selected groups of camera will be perfect).  so i mean i will rename my old photos and i want the camera labels changed also with the new renaming.
thanks
Mohammed

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Change images names after Align photos
« Reply #5 on: May 26, 2016, 06:22:51 PM »
Hello Mohammed,

This script renames the cameras by adding the folder name to the camera label (for example, for D:/data/project/current/IMG_0001.JPG the camera label will be changed from "IMG_0001.JPG" to "current_IMG_0001.JPG"):
Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk

for camera in chunk.cameras:
if camera.photo.path.count("/") > 1:
camera.label = "_".join([camera.photo.path.rsplit("/",2)[1], camera.label])
else:
print("Can't rename " + camera.label)
print("Script finished")

The second script works in the similar way but adds user-defined prefix for all the selected cameras:
Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk

string = PhotoScan.app.getString("Input prefix to be added to the selected camera labels:")
for camera in chunk.cameras:
if camera.selected:
camera.label = "_".join([string,camera.label])

print("Script finished")
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #6 on: May 26, 2016, 08:56:31 PM »
Dear Alexey,

The second script (selected by camera) is exactly what i need, Thank you so much!
But sorry please i don't need the old file name to be added after i selected the cameras and Rename them.
(for Example the old name "DSC_0001) and i want the new name not added to the old name like "20150607_Mohamed_photogram_0001''

Thank you in advance
Mohammed

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Change images names after Align photos
« Reply #7 on: May 26, 2016, 09:05:02 PM »
Do you wish to keep the index then? If so, you can use the following:

Code: [Select]
import PhotoScan

DELIMITER = "_"
chunk = PhotoScan.app.document.chunk

string = PhotoScan.app.getString("Input prefix to be added to the selected camera labels:")
for camera in chunk.cameras:
if camera.selected:
camera.label = "_".join([string,camera.label.rsplit(DELIMITER, 1)[1]])

print("Script finished")

In the script it is assumed that the index is separated by the DELIMITER separator, so if it is not underline, you can change it manually in the script body.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #8 on: May 26, 2016, 09:30:17 PM »
Dear Alexey,
Thank you so much but i'm really sorry for confusing you, i didn't want the index number i want to change the whole name.
Ex. DSC_0001    to     20150607_Mohamed_photogram_0550
Thank you
Mohammed
« Last Edit: May 26, 2016, 10:44:00 PM by tornado2011 »

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #9 on: May 27, 2016, 02:14:48 PM »
Hi Alexey,
I send to you a private message so when you send the script put it here, may some one else found it useful for his work.
I just wanna to change the whole name of camera label by select group of camera.

Many thanks Alexey for your effort
Mohammed

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Change images names after Align photos
« Reply #10 on: May 27, 2016, 03:14:08 PM »
Hello Mohammed,

The following script asks for the label prefix (same for all the cameras) and starting index:
Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk

string = PhotoScan.app.getString("Input prefix to be added to the selected camera labels:")
index = PhotoScan.app.getInt("Input starting index:")

for camera in chunk.cameras:
if camera.selected:
if camera.label[-4] == ".":
camera.label = "_".join([string,"{:04d}".format(index)]) + camera.label[-4:]
else:
camera.label = "_".join([string,"{:04d}".format(index)])
index += 1

print("Script finished")

the result of the script will give you the following result:
prefix_0011
prefix_0012
prefix_0013
...
providing that index has been set to 11. If the extension is present in the camera labels it will be kept.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #11 on: May 27, 2016, 03:18:35 PM »
Hi Alexey,

You are the best!  script work very fine.
Thank you million time,,

Mohammed.

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #12 on: May 27, 2016, 03:30:43 PM »
Hi Alexey,
the script works fine but why its still read the old name, i tried to change the path with the new rename but the sw can't find it.
see snapshot
Thanks
Mohamed

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Change images names after Align photos
« Reply #13 on: May 27, 2016, 03:58:03 PM »
THis one should also update the image paths:
Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk

string = PhotoScan.app.getString("Input prefix to be added to the selected camera labels:")
index = PhotoScan.app.getInt("Input starting index:")

for camera in chunk.cameras:
if camera.selected:
if camera.label[-4] == ".":
camera.label = "_".join([string,"{:04d}".format(index)]) + camera.label[-4:]
else:
camera.label = "_".join([string,"{:04d}".format(index)])
camera.photo.path = camera.photo.path.rsplit("/",1)[0] + "/" + camera.label
index += 1

print("Script finished")
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: Change images names after Align photos
« Reply #14 on: May 27, 2016, 04:01:11 PM »
Thank you so much!

Mohammed