Community Forum

Author Topic: Is it possible to modify loaded image?  (Read 159 times)

dobedobedo

  • Newbie
  • *
  • Posts: 12
    • View Profile
Is it possible to modify loaded image?
« on: December 05, 2017, 09:01:09 AM »
Hi,

When I tried to modified the loaded image with:
Code: [Select]
camera.photo.image = New_ImageIt always shows the error
'PhotoScan.Photo' object attribute 'image' is read-only

Although I am able to manage modifying it with:
Code: [Select]
width = camera.sensor.width
height = camera.sensor.height
for u, v in [(u, v) for u in range(width) for v in range(height)]:
    camera.photo.image()[u, v] = New_Image()[u, v]
The efficiency is terrible in this case. It costs around one hour to process a 1280*960 image.

The reason I do this is I want to apply two different linear regression model to the image based on its DN value, and New_Image is the image I calculated and wish to be used for further process. The concept is like this:
Code: [Select]
if DN >= criteria:
    DN = linear_model1(DN)
else:
    DN = linear_model2(DN)
Then the modified images can be used to process the orthomosaic directly so that I don't need to run photo alignment and other workflow again.
Any idea about how to achieve this would be very appreciated.  :)
« Last Edit: December 05, 2017, 09:39:24 AM by dobedobedo »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 7775
    • View Profile
Re: Is it possible to modify loaded image?
« Reply #1 on: December 05, 2017, 12:12:57 PM »
Hello dobedobedo,

I see two options to swap the images inside the camera container:

1.
Code: [Select]
path = "D:/new_image_path.jpg" #path to the new image
camera.photo.open(path, 0)

2.
Code: [Select]
path = "D:/new_image_path.jpg" #path to the new image
camera.photo.path = path

However, in both cases the new image should have the same image dimensions as an original.
Best regards,
Alexey Pasumansky,
AgiSoft LLC

dobedobedo

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Is it possible to modify loaded image?
« Reply #2 on: December 06, 2017, 03:58:51 AM »
The methods work! Thanks a lot.