Posts: 3
Threads: 1
Joined: Oct 2024
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
10-08-2024, 02:03 PM
(This post was last modified: 10-08-2024, 02:21 PM by damien.f.)
Hello everyone!
I'm struggling with python API to open a FITS image.
When I open a FITS picture with the menu "file->open" I have a prompt regarding picture composition : "none" or "NAXIS=3, NAXIS3=2,...,4". And when I select "NAXIS..." the image is correctly loaded into GIMP in RGB.
But when I use python pdb.file_fits_load() command, I have no options in order to specify none or NAXIS. thus my image is always in gray scale.
Also, with python command, I do not have multiple images as I have when I select "none" on the HMI (=> 3 images, one per color).
What should I do to have the image in RGB loaded by python command?
Thank you for your help!
Best regards,
Damien.
Posts: 6,386
Threads: 278
Joined: Oct 2016
Reputation:
566
Operating system(s):
Gimp version: 3.00RC1
As a work around you can try to call file_fits_load with the named parameter run_mode=RUN_INTERACTIVE this may make it show the dialog where you can select parameters manually.
Posts: 221
Threads: 41
Joined: Oct 2016
Reputation:
4
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
10-08-2024, 07:29 PM
(This post was last modified: 10-08-2024, 07:32 PM by trandoductin.)
I played around with this and notice the function file_fits_load returns one image but it creates 3 in memory which you can use compose them as RGB.
So i got this to work
def afittest(image,layer,file):
image = pdb.file_fits_load(file,file)
#images set in memory but not returned because return only one but we have 3 new images
l = gimp.image_list()
redImage = l[len(l)-2]
greenImage = l[len(l)-3]
blueImage = l[len(l)-4]
#compose them
new_image = pdb.plug_in_compose(redImage,layer,greenImage,blueImage,redImage,"RGB")
pdb.gimp_display_new(new_image)
Posts: 6,386
Threads: 278
Joined: Oct 2016
Reputation:
566
Operating system(s):
Gimp version: 3.00RC1
(10-08-2024, 07:29 PM)ttt Wrote: I played around with this and notice the function file_fits_load returns one image but it creates 3 in memory which you can use compose them as RGB.
So i got this to work
def afittest(image,layer,file):
image = pdb.file_fits_load(file,file)
#images set in memory but not returned because return only one but we have 3 new images
l = gimp.image_list()
redImage = l[len(l)-2]
greenImage = l[len(l)-3]
blueImage = l[len(l)-4]
#compose them
new_image = pdb.plug_in_compose(redImage,layer,greenImage,blueImage,redImage,"RGB")
pdb.gimp_display_new(new_image)
In Python you can use negative indexes to access list elements from the end: l[-1] is the last element, for instance. You can even use slices, so for instance: imgR,imgG,imgB=gimp.image_list()[-4:-1].
Otherwise, yes, the Images dockable dialog is your best friend, because it shows all images, even those that have no associated view/display, and there is even a button to create a view for the latter. It is also a nice way to check for lingering images after a script.
Posts: 221
Threads: 41
Joined: Oct 2016
Reputation:
4
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
thanks, more info by the master hehe.
Posts: 3
Threads: 1
Joined: Oct 2024
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
(10-08-2024, 07:47 PM)Ofnuts Wrote: (10-08-2024, 07:29 PM)ttt Wrote: I played around with this and notice the function file_fits_load returns one image but it creates 3 in memory which you can use compose them as RGB.
So i got this to work
def afittest(image,layer,file):
image = pdb.file_fits_load(file,file)
#images set in memory but not returned because return only one but we have 3 new images
l = gimp.image_list()
redImage = l[len(l)-2]
greenImage = l[len(l)-3]
blueImage = l[len(l)-4]
#compose them
new_image = pdb.plug_in_compose(redImage,layer,greenImage,blueImage,redImage,"RGB")
pdb.gimp_display_new(new_image)
In Python you can use negative indexes to access list elements from the end: l[-1] is the last element, for instance. You can even use slices, so for instance: imgR,imgG,imgB=gimp.image_list()[-4:-1].
Otherwise, yes, the Images dockable dialog is your best friend, because it shows all images, even those that have no associated view/display, and there is even a button to create a view for the latter. It is also a nice way to check for lingering images after a script.
Thank you very much ttt and Ofnuts!!
I was not able to use slices, I have an error:
➤> imgR,imgG,imgB=gimp.image_list()[-4:-1]
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: need more than 2 values to unpack
But using gimp.image_list()[-1] , gimp.image_list()[-2] and gimp.image_list()[-3] works like a charm.
With the example of ttt, I now have my RGB picture!
Thanks again!
Best regads,
Damien.
Posts: 6,386
Threads: 278
Joined: Oct 2016
Reputation:
566
Operating system(s):
Gimp version: 3.00RC1
(10-08-2024, 09:09 PM)damien.f Wrote: (10-08-2024, 07:47 PM)Ofnuts Wrote: (10-08-2024, 07:29 PM)ttt Wrote: I played around with this and notice the function file_fits_load returns one image but it creates 3 in memory which you can use compose them as RGB.
So i got this to work
def afittest(image,layer,file):
image = pdb.file_fits_load(file,file)
#images set in memory but not returned because return only one but we have 3 new images
l = gimp.image_list()
redImage = l[len(l)-2]
greenImage = l[len(l)-3]
blueImage = l[len(l)-4]
#compose them
new_image = pdb.plug_in_compose(redImage,layer,greenImage,blueImage,redImage,"RGB")
pdb.gimp_display_new(new_image)
In Python you can use negative indexes to access list elements from the end: l[-1] is the last element, for instance. You can even use slices, so for instance: imgR,imgG,imgB=gimp.image_list()[-4:-1].
Otherwise, yes, the Images dockable dialog is your best friend, because it shows all images, even those that have no associated view/display, and there is even a button to create a view for the latter. It is also a nice way to check for lingering images after a script.
Thank you very much ttt and Ofnuts!!
I was not able to use slices, I have an error:
➤> imgR,imgG,imgB=gimp.image_list()[-4:-1]
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: need more than 2 values to unpack
But using gimp.image_list()[-1] , gimp.image_list()[-2] and gimp.image_list()[-3] works like a charm.
With the example of ttt, I now have my RGB picture!
Thanks again!
Best regads,
Damien.
This is because as used in ttt's example, your images are indices -4 to -2 (which implies there are at least 4 images in the list). If you want the last three the slice is [-3:] (from -3 to whatever the end is).
Posts: 3
Threads: 1
Joined: Oct 2024
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
(10-09-2024, 09:02 AM)Ofnuts Wrote: This is because as used in ttt's example, your images are indices -4 to -2 (which implies there are at least 4 images in the list). If you want the last three the slice is [-3:] (from -3 to whatever the end is).
Indeed [-3:] get me the full array
Thanks again!
|