Allow user change photo labels (and update Container.item_label) at the same time.
Opened this issue · 2 comments
Discussed in #75
Originally posted by youngdjn February 1, 2023
This is potentially a Python newbie issue -- apologies if so.
I am trying to change the labels of the photos (Photo.label
) in my project, but this does not propagate to downstream places where I think the photo label is (should be?) used.
For example using this project, if I run:
import easyidp as idp
from pathlib import Path
msproj = Path("/path/to/project/example-multifolder.psx")
ms = idp.Metashape(msproj, chunk_id=0)
ms.photos[57].label
I get '100MEDIA-DJI_0165'
Then I attempt to rename them:
for i in range(len(ms.photos)):
ms.photos[i].label = "newlabel" + str(i)
ms.photos[57].label
and I get 'newlabel57'
.
But then I run back projection
img_dict_ms = roi.back2raw(ms)
img_dict_ms
And the labels in the returned dict are the original ones:
{'1': {'100MEDIA-DJI_0165': array([[4741.6161679 , 684.46603374],
[4735.11907978, 712.14368673],
[4718.00310275, 728.6865289 ],
[4722.27333877, 728.17479155],
...
And also when running show_roi_on_img()
it only works when I reference the photos by their original labels, like:
ms.show_roi_on_img(img_dict_ms, "1", "100MEDIA-DJI_0165")
and it doesn't work when I run:
ms.show_roi_on_img(img_dict_ms, "1", "newlabel57")
Can you suggest a way to fully change the labels?
The reason for this request is that I am trying to give the photos more meaningful labels so that I can more easily link the photo labels to the original photo files.
You are changing the "ms.photos.label". However, when using the roi.back2raw()
function, the parameter passed is "ms.photos.item_label", which is a dictionary, different from "ms.photos.label"
So to change the labels correctly, you need to modify the "ms.photos.item_label", here's my practice
new_dic = {}
for i in range(len(ms.photos)):
new_key = "newlabel_" + str(i)
new_dic[new_key] = i
ms.photos.item_label = new_dic
Notes
- After using
roi.back2raw()
,modifications will be stored in the *.psx file, which is irreversible, so please make a backup of the *.psx file. - I only modifed the "ms.photos.item_label", the "ms.photos.label", "ms.photos.label" hasn't changed. So you may need to re-read the *.psx file after saving it, or do what you did with "ms.photos.label" at the same time. But as I practice, it doesn't matter whether I do that or not.
You are changing the "ms.photos.label". However, when using the
roi.back2raw()
function, the parameter passed is "ms.photos.item_label", which is a dictionary, different from "ms.photos.label" So to change the labels correctly, you need to modify the "ms.photos.item_label", here's my practice
new_dic = {}
for i in range(len(ms.photos)):
new_key = "newlabel_" + str(i)
new_dic[new_key] = i
ms.photos.item_label = new_dic
Notes
- After using
roi.back2raw()
,modifications will be stored in the *.psx file, which is irreversible, so please make a backup of the *.psx file.- I only modifed the "ms.photos.item_label", the "ms.photos.label", "ms.photos.label" hasn't changed. So you may need to re-read the *.psx file after saving it, or do what you did with "ms.photos.label" at the same time. But as I practice, it doesn't matter whether I do that or not.
Please refer to this comment: #75 (comment)
Actually, EasyIDP only reads the *.psx files and unable to change that file. You may need to rename the labels every time you load that project.