Wednesday 22 April 2020

New "Readjust" feature in Gimp Unified Transform (NZRM Aerial Mosaics)

Unified Transform is a very useful capability in Gimp since about 2.10 that combines a number of transformation tools together, such as Scale, Rotate and Shear. I have used this tool extensively when creating aerial map mosaics for the NZ Rail Maps project.

To create an aerial map mosaic, I start with downloading the current aerial imagery layer for the part that I want to create a mosaic from, and then extract the map tiles from it (each is 4800x7200 although if at the edges of the layer they can be smaller) and lay them out in Gimp. Using a grid size of 4700x7200 and snapping to grid makes this quick and easy. If the tiles need to be scaled to a multiple (usually this is x2 in each direction) then use the Scale Layer function to achieve this with Cubic interpolation.

Then import the historical tiles, and the first thing you need to do with downloads from Retrolens is to crop out the borders. Apart from the copyright banner along one border there is also the negative mounting frames, which I presume are cardboard like slides. Sometimes I need to get so close to an edge that I'll be forced to include part of the border and then use masking to hide it. When I first started doing these mosaics, I didn't bother cropping the borders and instead I just masked them off every time.

The next step is to overlay the historical tiles on to the current background tiles. This is where the Unified Transform tool comes into play. The first thing to do is to find a common point near one of the overlay's borders. Then drag the pivot from the centre of the overlay to that point on the overlay, and then set the overlay's opacity to zero. Then drag the overlay until the pivot is in the same place on the base layer.

Then ensuring that the Constrain and From Pivot options are set properly (Scale option turned on), and then scale and rotate the overlay until the rest of it lines up with the base. I have set keyboard shortcuts to control the opacity without having to set this with the mouse (this is Tool Opacity in the keyboard shortcuts section) and also canvas rotation with more shortcuts so I can quickly turn the canvas to make the view work better for me.

The new "Readjust" feature addresses a fairly common issue I have with lining up the overlay with the base where the part I want to match up is nowhere near the edge or the scale handles. It can be somewhere near the middle, for example, and I need to be able to rotate or scale without having to zoom out to get the edge or scale handle in view and then lose sight of what I am trying to line up. Clicking the "Readjust" button creates a new transform control frame that fits in the current view in the window instead of being aligned to the edges of the image, which means you can get a set of edges and adjustment handles anywhere on the overlay. This is particularly useful with some of the quite big images I am working with for ensuring there is perfect alignment especially where two overlays overlap each other and will make a big difference in creating these mosaics. The only issue I have found with Readjust is that it moves the pivot when used, and the option for locking the pivot doesn't seem to achieve this, so I have to drag the pivot back to where it was before but it still seems to be OK. This is likely to make a huge difference in creating more accurate alignments with mosaics than I have been able to achieve in the past.

Normally for Unified Transform these days I will use Cubic interpolation for everything. I used to use LoHalo but I doubt that any extra quality it might have produced was significant so Cubic seems to have little effect on the final quality.

Monday 20 April 2020

Raspberry Pi as Livestream Player [4]... Or Conventional HTPC?

So after recent posts talking about Raspberry Pi possibilities I am probably going to forgo using my Pi as a media player because I have pulled out an old Intel DB75EN board that used to be a desktop computer here and it plays videos very well. So that old computer can be repurposed. It needs a smaller chassis than a tower to fit well into the bedside cabinet. The Silverstone Milo ML03 low profile desktop case is an interesting one to look at because it can use a full size power supply, unlike most such chassis which use TFX power supplies.  So this will be considered as an option. The spare desktop board I have will fit in it, and although it doesn't come with a power supply, I have a few spares around. Silverstone has especially targeted the HTPC market and produces a considerable range of different chassis, some of which are in the Mini ITX form factor, and others like this one will fit regular MicroATX boards.

It has an interesting design feature in that the internal PSU fan, which normally draws air out of the case, is relegated to drawing its own air supply through a grille in the bottom of this chassis, which is OK and potentially reduces noise from the fan, but also means it won't be cooling the inside of the system. That means an extra fan may be needed in the chassis, and due to its size 80 mm fans would need to be used, the potential downside of these being they tend to run at a higher speed and make more noise. In this instance with the low demand on the system I would try running it without a chassis fan on the assumption with the CPU vent in the top that hopefully there should be enough ventilation given that the system isn't under especially high load. However if fans are needed it can support more than one being installed which makes it possible they might be able to move enough air without making too much noise.

Reading this reviews for this product, any small case has its limitations, there are always going to be some compromises when cutting case size down and making it possible to fit everything in. This chassis is wider than some of the other desktop cases I have seen, but also not as deep, so it is swings and roundabouts. Being able to fit a regular ATX power supply (maximum depth of 140 mm) is a big plus as they are cheap and easy to come by and the smaller ones, apart from being harder to find, in some cases are also less reliable. However its front panel USB ports are USB3, and since the board I have doesn't have USB3 on the board, I would have to get a Silverstone adapter cable to adapt these. With a specialised chassis like this one, do your homework. Get the manual for it off the website and have a really good look at the measurements and other information to be sure everything will fit inside. In my case it looks like the adapter cable mentioned above is all that would be needed and, especially as I would not put an optical drive inside, it would go together OK, with no accessory cards and just the standard CPU cooler. But someone who needed extra cooling solutions or lots of drives might struggle. I would find a SSD desirable as well because of less noise and higher reliability, but that costs extra $$ of course.

In the past I also used a Mini-ITX system, part of the attraction being that I could buy a Mini-ITX board with integrated CPU at a lower cost than a separate board and CPU. However such boards are not really that easy to come by, or cheap, these days, and the best deal you can really get on Mini-ITX is an ASUS board for $150 and then you still need to buy a CPU for another $100. Since I can get a microATX board for about $100, it is really a premium price for Mini-ITX plus the extra cost of a chassis which tend to be dearer as well, and uses non-standard parts. In fact many of these current boards with a separate CPU are going to struggle to keep within the limit of power supply capacity on a lot of Mini-ITX chassis (the Antec I have with my AMD E350 board in it has only 60 watts) and it's possible with the passive cooling and the size of a regular CPU heatsink/fan that things might not fit and it might get too hot inside.


So that is another alternative to upgrading the Pi, which I can find another use for that isn't so demanding as video playback, which obviously gives it a hard workout.

Saturday 18 April 2020

NZ Rail Maps Technical Review 2020-04-18

So we are now at Qgis version 3.10.4 for the NZ Rail Maps map production task. Back a way we had a lot of trouble with Qgis with WMTS layers which were unusable at that time. Since then however we haven't been able to replicate the problem but we suspect that their code has bugs in WMTS handling and possibly wasn't dealing with a temporary issue with the WMTS feed. We had to go back to 3.4.4 running on a Stretch VM to be able to continue editing our projects until we decided to have another go with the latest LTR and it seems to be OK for now.

Also looking back a few posts we see a reference to saving mosaic tiles as a group to reduce the overall number of them. This is one of several possible solutions to a number of situations. One of these situations is when we have to upscale Linz imagery that is at 0.3 m or 0.4 m resolution in order to match the kind of scale that we get in images we download from Retrolens. From experience, a pixel height/width no greater than 0.15 m is needed to be able to match 1:4300 or 1:5500 scale and get the full resolution of the Retrolens images when we export out the mosaic tiles to be used in Qgis.

The question then to be solved was how to change that into 4800x7200 tiles because each of the original base images is now several times larger in each dimension. For example these days we will commonly scale a 0.3 m resolution tile by 200% in each direction which makes the new pixel size 0.1 m. We did scale 0.4 m tiles to 0.1 m at one time but for the rare times we use them will try to get away with 0.2 m by again scaling the base 200% both ways. Obviously the original 4800x7200 tile now becomes four if we have doubled in both directions.

One way we attempted to resolve this was to create a special grid of 4800x7200 tiles by adding a part suffix to the original filename so that XXXX1-YYYY2 would become XXXX1.2-YYYY1.3 where the .1 or .3 suffix indicated a position in a particular grid. Special grid templates would be used in Gimp to help split the image into the correct grid segments. This was tried with Northland aerial mosaics in particular but has now been ditched in favour of simply creating a larger mosaic tile made up of multiple 4800x7200 tiles. This is much easier than running the special script to create all the special world files for each sub segment that would need to calculate the top left coordinates to tell Qgis where to draw the tile.

The great advantage of creating one big mosaic tile is that only one world file is needed and it only needs to specify the top left coordinates of the big tile. So you can make that tile cover as big an area as you need as long as you can replicate the top left coordinates and the pixel size in the world file. Typically we are just taking the world file for the top left tile which is based on the original top left tile even though it has been scaled up to a new size, and just changing the pixel resolution parameters in there to reflect the new resolution.

We have been looking at the Northland mosaics again this week and have just been removing the grids and exporting the mosaics again as one big mosaic tile for each station because we never got around to creating the grid segment world files which was very complex and hard to do so this is getting these mosaics back into our Volume 1 Qgis project so they can be put to work.

Thursday 2 April 2020

Linux video editing, revisited

Some way back, I don't recall exactly, I talked about Linux video editing. When I set up mediapc the idea was that was going to be its key function. Then I ran into some roadblocks trying to find FOSS software that could do this, and just gave up and stuck with Avidemux, which can do a few basic things but does tend to crash from time to time (latest is it crashing every time I try to extract 14 seconds from a 50 minute clip). To be true, I also did look at some audio mixing software that was Linux shareware, had a quick play with it and left it because I didn't have the need at that time (Ardour). It might be completely free now, I'm not sure, but I expect something like it will get more use from me in the future the way it looks like things are going for me. 

Anyway, back to video editing. This blog post by a Red Hat guy was really enlightening, because his experiences with some of the FOSS packages out there really mirrored mine.
Clearly he reached a conclusion out of many editors he looked at (I looked at most of them as well), Blender is the only one worth bothering with, all the rest are cr@p. So at least I can be sure it isn't just me that many of these programs crash non stop, etc.

mediapc and playerpc will be getting Blender installed in them pretty soon for various tasks and it looks like once I get the hang of it, it should be able to do everything I need. We shall see.