Jan 26, 2023

ImageStitch, aerial photos and a surprise

Aerial photos are usually taken with overlaps, it is a perfect application for ImageStitch to generate a mosaic of the aerial photos from one flight line.

First, let's import the photos from FlightLine 3196it is somewhere in Antarctica. The data is from the Center for Remote Sensing and Integrated Systems (CReSIS). 

There are 12 images:

Then run ImageStitch on the imported images, on Mathematica 13.0.1, the result is the following, clearly something wrong.


For the reference, the image from Google Earth, 

The plan was to extend the function from the previous post on ImageStitch, we only need a function to work with two images, then we can use Fold function to apply it incrementally over all the images, since the photos are taken in a sequence, for example:

imagelist = {image1, image2, image3, imaga4};

Fold[ourimagestitch[#1, #2] & , imagelist[[1]], imagelist[[2 ;;]]] 

===>

ourimagestitch[ourimagestitch[ourimagestitch[image1, image2], image3], imaga4] 

 A Surprise

Mathematica 13.2 is out, ImageStitch function is updated. Our organization only has the license for 13.0.x version right now. So, I downloaded Mathematica Engine 13.2, run the same code in Jupyter Notebook, the result is great.


Kudos to the developer!

Jupyter Notebook: ImageStitch and Aerial Photos


Mar 28, 2022

Using Wolfram Engine with Jupyter Notebook

I’ve been using the free Wolfram cloud for a while; it is actually very capable for small projects. Several tips:

  1. It can’t upload any files, put the data somewhere online, then use Import[url] to get the data

  2. Each command can only run in a limited time (several minutes?), and sometimes reducing the size of data can help the job run through, for example, ImageResize[image,Scaled[1/2]].

  3. Learn some keyboard shortcuts, especially on cell formatting: Keyboard Shortcut Listing for the Wolfram Cloud.

  4. The most important thing: download your notebooks and also save a pdf copy. The file expires after 60 days, the user can’t open and download the expired files.


You probably can guess what happened to my files, they are all expired. I am not complaining here, it is free service anyway. To avoid this issue, I decided to try Free Wolfram Engine with Jupyter Notebook. They can be connected by WolframLanguageForJupyter. I am not going through the installation part; it is well documented for each product. I’ve created a sample notebook ImageStitch.ipynb with JupyterLab (a better interface than the classic Jupyter notebook). (Note: if it doesn’t load properly, try to reload it again). I may try other connectors later, the one used here is directly from Wolfram, however it doesn’t support auto-completion.  




Mar 24, 2022

Update: Learning Mathematica Slowly

I am on an extremely slow journey to pick up Mathematica again, one is that the current Mathematica is massive, the second is on me, in short “small brain”, that it is difficult to switch among several different programming languages. I mainly do coding with Python and JavaScript. I’ve tried to learn Julia and Mathematica at the same time since January, and got confused very quickly. So, in the next several months, I will focus on Mathematica first.


Currently reading: Wolfram Language Tutorial: Fast Introduction for Programmers

This book mainly explores Wolfram language on the level of grammar and syntax, it may fall short on emphasizing the importance of functional programming. Even though it plays a much minor role in Python, the basic idea of functioning programming lives well inside the Python ecosystem, for example, pure function (lambda) and map() are used frequently. If this book can absorb more materials from Functional Programming—Wolfram Language Documentation, it definitely helps a Python programmer understand the paradigm of Wolfram Language better.


The book comes with the notes for Java and Python programmers. The notes on Python are too simple and almost lose their purpose. The following are two examples:

  1. List comprehension: 

In Iterators | Wolfram Language Fast Introduction for Programmers, it says "Using Table in this way is analogous to using the [... for ... in ...] list comprehension construct in Python, though it has somewhat richer semantics.”. What’s the richer semantics? The list comprehension in Python is versatile, it has a basic format: newList = [ expression(element) for element in iterable], and combined with conditions(if/else), lambda function and nesting, it can do lots of things in a concise syntax. Here is not arguing the feature in which language is more powerful, it is mostly a missed opportunity for a better explanation on Wolfram language.

  

  1. f-string formatting:

In Strings | Wolfram Language Fast Introduction for Programmers, it says “TemplateApply in the Wolfram Language works similarly to Python's % or format function, except inline computations using <* ... *> are not supported in Python.” This claim is not accurate, Python’s f-string (introduced in Python 3.6) does the exact same thing. The screenshot shows some examples.



Jan 11, 2022

Code update: Stock Market Performance in January

This is a simple code update for Stock Market Performance in January, it is tested with the free Wolfram Cloud

The main change is that FinancialData now returns a TimeSeries object.
I haven't touched Mathematica 10,11 and 12, learning 13 on Wolfram Cloud right now. Mathematica has changed a lot!!

Mar 26, 2014

Geospatial function: Point in Ploygon Test

There is an excellent post on point in polygon test from Mathematica Stackexchange.

Point in polygon test is one of the most useful functions when processing Geospatial data. Unfortunately, there is no official built-in function from Mathematica yet. Here is an example of showing usefulness of this function.
We have some data on Greenland icesheet thickness in format of {lon,lat, thickness}.


Our goal is to make a map to show the thickness of icesheet.
First try with ListDensityPlot:


You can see it is not working well, we need to limit the plot region inside the boundary of Greenland. Here is the place we can use the point-in-polygon test. In this example, I use inPolyQ2 from the answer by Simon Woods:


Still not right? What's wrong? The trick is to increase MaxPlotPoints  to 100 at least:
ListDensityPlot[data, PlotRange -> All,
 ColorFunction -> (ColorData["Rainbow"][1 - #] &),
 RegionFunction -> (inPolyQ2[greenland_ploygon[[1, 1]], #1, #2] &),
 MaxPlotPoints -> 150, MeshFunctions -> {#3 &}, Mesh -> 10]


It looks like a real map now.