Removing white borders

293 views
Skip to first unread message

Mariana Scott

unread,
Nov 16, 2016, 10:22:51 AM11/16/16
to Py-ART Users
Good morning,
Would anyone know how to remove the bordering white spaces from an image? I have tried the first two Google search pages and... nothing :| I'm using matplotlib to plot the map.
I'm looking to take my image and put it in Google Earth, so no borders and transparencies ar my biggest problems right now.


I know this isn't directly related to PyART so let me know if this isn't an appropriate topic for this and I'll delete it.
Cheers,
Mariana

Kai Mühlbauer

unread,
Nov 16, 2016, 10:54:35 AM11/16/16
to Mariana Scott, Py-ART Users
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

Mariana Scott

unread,
Nov 16, 2016, 1:05:41 PM11/16/16
to Py-ART Users, feli...@gmail.com, kai.mue...@uni-bonn.de
Thank you Kai,
Unfortunately I'm not saving the image, so I'm not saving the image so I'm not using the fig.savefig call.
...Its kind of a long story, but I'm using numpy to save the matplotlib figure to data:

fig.canvas.draw()
 
imgData = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
imgData = imgData.reshape(fig.canvas.get_width_height()[::-1]+ (3,))

Kai Mühlbauer

unread,
Nov 16, 2016, 1:21:28 PM11/16/16
to Mariana Scott, Py-ART Users
Hi,

There is also a reference to the fig.patch.set_alpha() function which works for me.

I'm not sure, if tostring_rgb() will work at all with transparency/alpha channel. If it returns just rgb you've bad luck, because information about alpha channel is lost.

You might try to set the fig and ax patches to some unique color and fix it later in your final image array.

How do you feed the image array to Google maps?

Cheers,
Kai

Mariana Scott

unread,
Nov 16, 2016, 1:39:14 PM11/16/16
to Py-ART Users, feli...@gmail.com, kai.mue...@uni-bonn.de
Thanks again! I will take a look at fig.patch.set_alpha(), and will also make sure tostring_rgb() will work with transparency.

I used Google Earth as an example since most people are familiar with it and transparency and border padding are unacceptable in that application. I'm actually putting the images in an HDF5 file that will be read and mapped with Java's MapAPI. Its the data type the that costumer is used to, and they have mapped other fields HDF5 in the past (namely WRF variables, but plotted with Java, not Python).

Cheers,
Mariana

Mariana Scott

unread,
Nov 16, 2016, 2:11:26 PM11/16/16
to Py-ART Users, feli...@gmail.com, kai.mue...@uni-bonn.de
FYI, the way to get RGBA to numpy is through the fig.canvas.tostring_argb() call :)
Reply all
Reply to author
Forward
0 new messages