How can I generate a transparent SciLab graph that I can superimpose over another image?
Hello Heinz,
In fact it is not possible within Scilab, but you can do this by exporting the graph as svg then edit the file e.g. with Inkscape.
S.
Yes. I had imported the Scilab svg into GIMP, touched the white background with the wand and exported png
Hello Heinz,
…True transparency is not possible within Scilab…
Yes, but if you only need the effect of overlapping colors, you may try the pixel_drawing_mode.
https://help.scilab.org/docs/2025.0.0/en_US/pixel_drawing_mode.html
Best regards,
Philipp
OK, understood.
In general I would suggest to work completely within Scilab without export to svg and image processing software like gimp.
Then you can do this without transparency at all.
It depends a little of the type of map you need.
version A:
use Scilab toolbox: celestlab
Within this, there is a function to plot borders: CL_plot_earthMap()
However I think you will get only borders of coast lines (continents, islands, lakes)…not “in between states borders”.
Version B:
load a map as an image via imread()
…e.g from IPCV toolbox.
Display the map with Matplot()
However this might become tricky, since you will have to deal with correct map projection if you want to overlay long/lat coordinates.
Hint: Google search EPSG4326 and EPSG3857
However, if you have all you need you can play with several axes …
E.g:
axis1: map pixel coordinates (right/top)
axis 2: lat/long coordinates (left/bottom)
newaxes()
is your friend here.
The image shows a combination of:
- map read via
imread()
- borders used from
CL_plot_earthMap()
… (e.g.: coastal line) - state border using
plot()
… data from Germany Detailed Boundary: Free Vector Map - Cartography Vectors, in this case thegermany-detailed-boundary_917.kml
Best Regards,
Philipp
OK, this has nothing to do with transparency. Just display the background, then plot something over it. As Philipp says using newaxes() can help.
S.
Hello Heinz,
just to mention:
In principle it is possible to generate opaque graph images.
The image below was done in inkscape, by:
- loading a background image
- loading a Scilab generated diagram, saved as a RGBA image
To be precise, the graph was:
- generated using
plot()
command - exported via
xs2png()
as an RGB image - reloaded via IPCV
imread()
as a 3 channel matrix - combined with an alpha channel (define white pixel = transparent)
- saved via IPCV
imwrite()
as an RGBA image
However, although the quality of the exported graph ( xs2png()
) is quite good, the quality of the imported graph with imread()
is rather bad.
The image (background + graph) could also be generated in Scilab itself using Matplot()
.
Just Matplot()
the background and afterwards Matplot()
the graph-image.
I consider this approach more as a practice in the way of “What is in general possible?” rather than a solution.
The approach itself is maybe more useful, if the content of a figure could be stored as a matrix. I mean: xs2png()
stores the figure content as a image…something like xs2three-channel-matrix()
should be possible.
Note: I used Scilab 6.1.1 and IPCV 4.1.2
Best Regards,
Philipp
This is just a question of display method. Matplot is used for this and doesn’t do any interpolation when scaling the image so the visual quality may look bad although it may look fine when displayed with system tools.
S.
Just another note:
xs2bmp()
stores a 24 bit image, hence the result is a RGB image.
xs2png()
stores a 32-bit image…hence the result is a RGBA image.
I guess however, that the “alpha” part is ignored or set to a value equal to “no opacity”.
I could imagine that it is possible to build a new functionxs2pngWithAlpha()
that is
- based on
xs2png()
- takes a user input as definition for transparent color
- searches the figure content for this color
- sets the alpha channel at these pixel locations to “transparent”
- saves the result as a png file
I mean, at some point xs2png()
must know the RGB values. So it should be possible to compare these against a user defined pixel value.
If so, Scilab would have a native function to generate transparent graphs.
Hello Philipp,
Feel free to look at the xs2png sources to see what can be done.
S.
Hello Stéphane,
I do remember your comment on the subject here…
I am sorry but adding opacity in the general Scilab graphic model is a HUGE work beause it would necessitate to revamp the whole renderer module and it cannot be something else than a long term milestone. However, if you can afford to hire a Java/C++/OpenGL specialist we would be glad to help him to dive into Scilab project!
So, although it will most likely exceed my programming skills … out of interest I’d like to have a look.
Just: Can you give a hint where to look?
BR
Philipp
Hi,
I put together some code for creating a transparent image from a figure.
Before posting the function gui2rgba
, I’d like to ask if it is OK to put the code here. This is because it heavily relies on gui2bitmap
.
Best Regards,
Philipp
Hello,
You should contact the author of gui2btimap and ask him to add your function in the toolbox.
S.
Hello heinznabielek
Is this something like that you want to do ?
The Map is a JPG file
On top I plotted random dots
And save it PNG and JPG
Using SCICV toolbox
Plot_on_Map.sci (809 Bytes)
BR
François
Beautiful. Yes great. But how exactly do I arrange correct longitude and latitude? Heinz
If your map grid coordinates are horizontal/vertically like in the example below, it is rather easy…you just need to boundary coordinates of your map [left, right, top, bottom] .
E.g. you need to search for the most west, east, north, south coordinates that are represented by the map.
Plot the map via Matplot()
or imshow()
If you use Matplot()
make sure to set axes margins to [0 0 0 0];
Than use newaxes()
to have an new axes entity for the lat/long coordinates of your data.
Adjust the data_bounds
of the axis to the map boundaries.
That should do the trick.
Best Regards,
Philipp