viridis Posted August 13, 2017 Report Share Posted August 13, 2017 (edited) Been trying to master the Heightmap import from the editor, found quite limited in input options as Palaxin's noted in the Height guide. As I have some background on scientific imaging software I started playing around with elevation data here and there and found that there is need for more control on horizontal scaling (the map) related to height scaling. Aswell as (maybe) simpler way of preparing image data for heightmap import in the 0ad editor. ImageJ is an open-source image processing and analysis software written in Java. It is a multi-purpose piece of software very well suited when working with (very) different types of images, specially for scientific analysis. It has the advantage of allowing the extension of software via macros (very simple scripting language for repeated processes) and plugins (Java coding), so anyone can share any piece of code for automating the preparation of geospatial data for the (great but currently limited) heightmap import in the 0ad editor. One of the problems I found first is when I try to prepare a very small map (e.g. 128*128 pixels) having the height values from 0 to 255 (8-bit per pixel) the elevation (z-axis) has too much range whereas the map surface (x,y axis) has too little. Moreover, even if you don't have this problem, you may find in the need of controlling the z-axis scale independently from x,y (to obtain not too steep mountains or not too shallow cliffs, etc. depending on the case). This is precisely the problem I am going to address below. Preparing your system Install ImageJ from its download website (I recommend using your distribution repository if you use GNU/Linux or the platform independent download for other system if you already have Java already installed as ~99,99% people does , if it does not work refer to the documentation or try your platform download ). Download elevation and/or bathymetry data. For simplicity I've selected NASA Blue Marble image series as with this data source you have elevation and bathymetry on the same scale so both maps fit perfectly. I'll use the C1 area that includes the Mediterranean Sea as can be seen here. And download both the topography and bathymetry. Remember using right-click/save-link-as... cause the images are huge and you don't want to crash your browser. Select in both the same areas. I've picked C1. Basic map preparation Start ImageJ, you should see something similar to this: It's a tiny window for a great program don't let you misunderstand this: size in this case DO NOT matter. Open the elevation file, either using menu File/Open... or drag and drop. It is quite big, I strongly recommend you downsample (scale) it before continuing. So click menu Image/Scale... or just press Ctrl+E. I'll pick 128x128 px for showing you the problem with this kind of tiny sizes. I recommend "create a new window" option as I have experienced some weird problems if not. Just close the source image after finishing. If you believe your machine and patience can stand huge images skip scaling. If you prefer cropping than scaling try yourself, this is beyond the scope of this basic tutorial. Just try menu Plugins/Macros/Record... before cropping and guess how to repeat exactly the same crop in the bathymetry image. Further on this: write me or comment this and I will try to post and advanced tutorial on this. Maybe you've seen an error in the log: <Out of Memory>. If so you will have to close ImageJ and start it from the command line with the memory option. In my GNU/Linux it is -x (I guess is the same in other systems, but maybe with whole path before the command in windows): imagej -x 2048 As 768 MB is currently the default limit, and I have 6GB I guess 2GB will suffice (2048 MB). Of course do not reserve too much memory or your system might crash (you can see the free available memory in your task manager or sort-of). Now you can repeat 2, 3 steps until you achieve your wanted image. Close the big one, you want to preserve your memory. If you want to check the available memory ImageJ ships with a tiny monitor: menu Plugins/Utilities/Monitor Memory. You'll see a new tiny window and if you click on it the program will force garbage to be collected and reduce the memory used. This is very handy, if you find the memory usage is growing too much just click the monitor. Also you can click the status bar of the main window and there will appear the program info including its memory usage. Save your file. Either using menu File/Save... or hitting Ctrl+S. The default tiff file will suffice and preserve our original 8-bit pixel depth data. Repeat steps 2-5 with the bathymetry data. You should end up having two (not so big) images with the desired data. Now the magic comes. As I've mentioned above as NASA data uses the same scale and regions for all maps, now we have both elevation and bathymetry data from the very same region. Let's join that. We will use the image calculator. Think of it as a per-pixel calculator, so having 2 opened images of the same size from the same region you can combine it's data and finish having a bathymetry+elevation image. If you hover your mouse over any of the images you will see the value of the pixel under the mouse in the status bar, such as: x=23, y= 46, value = 125 note that x,y coordinates might be expressed in pixels or in inches or any length measure. Remember the value is the 8-bit value (0-255) for each pixel. If you explore a bit, you'll note the elevation image store 0 in the sea level whereas in the bathymetry the earth (above water) level is stored as 255. This gives us the clue to guess the kind of calculation we should choose. Now click menu Process/Image Calculator: So if we add the two images we will have both bathymetry data (from 0 to 255) and elevation data (from 256 to 511) merged into a new image. Please, note that if you do not use 32-bit result you will obtain an 8-bit data with the result of data loss (because with 8 bits you can store up to 256 values). Create a new window is also recommended option always. bathymetry + elevation = result + = Now, when you start thinking you have the perfect image to import on the 0ad editor, you save it (tiff will maintain all your precious data), then you just need to change the image type to RGB (menu Image/type/RGB color), then save it (menu File/Save as/BMP). Go to the 0ad editor import heightmap and get a horrid result: But this is not the end of the tutorial. Remember the z-axis (or height) scaling problem? Here you can see it. Let's address that. Ok, let's return to ImageJ and close anything but the result window (or reopen the tiff saved in 8). Click menu Plugins/3D/3D Surface Plot) There goes the result. The appearance is similar to the map generated by the editor, but you have now 3D superpowers. Have a look and play around: above you can change the visualization type (drawing as a mesh, dots, etc. and colors). At the right you can see Scale (zoom the visualization) and the most important z-Scale. Change the z-Scale value until you like the result and take note of the z-scale value (in my case 0.11). Return to the result window (elevation+bathymetry). Click menu Process/Math/Multiply... Type your desired value, OK and voilá! The image might have appear to become invisible, but the data just have changed (each pixel value has been multiplied by 0.11) You can save this tiff with another filename, such as "corrected" or -0.11 or as you want. Then repeat step 8 (type RGB save as BMP) and import it in the editor. THIS IS INCOMPLETE. SORRY FOR THE INCONVENIENCE BUT I'LL TRY TO FINISH THE TOPIC WHENEVER POSSIBLE. Edited August 14, 2017 by viridis incomplete 2 1 Quote Link to comment Share on other sites More sharing options...
niektb Posted August 13, 2017 Report Share Posted August 13, 2017 Years ago, I created a small tutorial video about using real world height data I never stumbled across OOM data... 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.