This example shows how to cut a region in the shape of a particular country out of a larger image. The image used is one of NASA's "Blue Marble" images of the Earth as seen from space in natural color. We will create a smaller image that shows only the region within Afghanistan. This same method can be used to cut out images that fit other countries, such as the United States, or regions such as Europe. Like any operations with larger images the operations in this topic should be performed on a reasonably fast computer that is equipped with plenty of RAM.
NASA's Blue Marble series of images provides spectacular views of the Earth as seen in natural color. Visit http://visibleearth.nasa.gov and search for "Blue Marble" to find them. Since web page URLs frequently, using a good search engine such as Google with search terms like "NASA", "Blue Marble", "land_ocean_ice_8192.tif" and similar may be required to find the images.
This image and others from the Blue Marble series is on the Manifold download site as well.
Step 1: Import and georegister the image
This example uses a medium resolution image downloaded in TIF format from the NASA site. It is 8192 pixels wide and 4096 pixels high and named Land_ocean_ice_8192.tif. Import the image using File - Import - Image. For brevity, henceforth we will refer to this image as "the image" instead of using the long name.
According to the NASA web site the image is in Latitude / Longitude projection, that is, no projection.
We import the image into Manifold. This particular image is very useful for maps showing land regions since it already uses transparent pixels for all ocean regions.
Because the image has been imported from ordinary .tif format (which does not save projection information) and not from GeoTIFF format (which uses the same .tif extension but does save projection information), there is no projection information available to Manifold and so it is imported using Orthographic projection. Manifold recognizes that as a sign the projection may need to be manually assigned and so when we first open the image Manifold will display an info bar advising us the projection in use has not yet been verified.
Our first tasks are to verify the projection and to georegister the image, which in this case consists of correctly assigning the projection to be used. We can accomplish both tasks by clicking on the info bar and then entering the correct projection parameters into the Assign Projection dialog that pops up.
If the image is 8192 pixels wide and the width of the image is 360 degrees (which it must be to cover the entire Earth in Latitude / Longitude projection) we know that the local scale in the X (width, East - West) direction is:
360 / 8192 = 0.0439453125
If the image is 4096 pixels high and the height of the image is 180 degrees we know likewise that the local scale in the Y (height, North - South) direction is:
180 / 4096 = 0.0439453125
To georegister the image, we click on the info bar and then use these values in the Edit - Assign Projection dialog.
The Edit - Assign Projection dialog comes into play when we import images from formats, such as ordinary TIF, that do not store projection information. We use it to tell Manifold how the coordinate numbers in the imported component should be interpreted. In this case the Local scale values happen to be the same for both X and Y. Both are 0.0439453125.
In addition to changing the Local scale values, we also enter -180 into the local offset for X and -90 for the local offset for Y. Where did these numbers come from? An experienced user will know that images from geographically unaware formats will be imported with positive coordinates only. However, an image in Latitude / Longitude projection will span both negative numbers and positive numbers in the range -180 to +180 degrees longitude and -90 to +90 degrees latitude. The coordinate system for the image must therefore be offset by -180 in X and -90 in Y so that half of the image uses negative numbers in longitude and latitude as occur in Latitude / Longitude projection.
An inexperienced user will not normally remember (or know how) to specify the Local offset numbers. Instead, the user will discover the above numbers after showing an image in a map together with an accurately georegistered drawing or other component. If Local offset is left at 0 for X and Y the image will be placed so that the lower left corner of the image is at the intersection of the Equator and the Prime Meridian. By changing the X local offset to -180 and the Y local offset to -90 the image is moved correctly into place. Inexperienced users usually find the correct Local offset numbers in a trial and error process like that shown in the Manually Georegister an Image topic.
Step 2: Show in a map with a drawing
We will import the Countries drawing from the Manifold CD. This is a drawing in Latitude / Longitude projection in the Countries lowres.map file. We import it using File - Import - Component to import the drawing from the .map file.
Create a map using the Land_ocean_ice_8192 image and open the map so created.
Next, drag and drop the Countries drawing into the map.
The Countries drawing appears in the map using default formatting.
Because the map was created using the Land_ocean_ice_8192 image it is in Latitude / Longitude projection and the Countries drawing is also in Latitude / Longitude projection. Just to be sure the drawing is in exactly the same projection used by the map and by the image, we will right click onto the Countries tab in the map and choose Project to Map. This guarantees the drawing is in the same projection as the map and will assure maximum speed.
The image will be hidden by the areas in the drawing. We are interested in seeing only the boundaries of the areas so that the regions underneath the areas in the drawing can be seen.
To make the image visible, click on the background color well for areas and change the background color to transparent color.
The result is an upper drawing layer that has transparent color for area backgrounds. The effect is as if we replaced the area objects in the drawing layer with boundary lines. The image is now visible and can be seen to be perfectly georegistered.
If we would like to have the area border lines stand out more, we can change the area border line foreground color from the default dark gray to black.
Now is a good time to save a copy of the .map project.
Step 3: Select image pixels in Afghanistan
We now will select pixels in the image that are within Afghanistan. To do this we will first select the area representing Afghanistan in the drawing and then transfer the selection to the image.
Zoom in to Afghanistan. Because we changed the area background color to transparent color we don't see the "inside" of the areas. All we see are the boundary lines for the areas, but each country shown in the country drawing is represented by an area. We can click within the boundary lines of any country to select the area representing that country.
Using Select Touch, click on the Afghanistan area to select it. The entire central part of the Afghanistan area is seen in red selection color. The entire area is shown in red selection color because the drawing contains areas and not just boundary lines. It only appears to consist of boundary lines because we have changed the background, color of the areas to transparent color.
We will now start editing the image based on the selection in the drawing. Click on the image's layer tab in the map to make it the active layer.
To transfer the selection to the image we launch the Image - Transfer Selection command. We choose to modify the image and check the box for the Countries drawing in the Using pane. Press OK. There is no immediate change in the appearance of the map because the red selection color that was shown in the drawing is now shown in the same location for the region of selected pixels in the image.
We double-click on the Countries layer tab in the map to turn it off and then click on the image layer tab to make the image layer the active layer again. Now that the drawing is no longer displayed in the map we can see that the selection is a region of pixels in the image.
Step 4: Crop image to selected pixels only
Our objective is to create an image of Afghanistan only. To do that we begin by cropping the image to Afghanistan only and then we will delete all pixels except the selected pixels.
We will begin by cropping the image to just that rectangular extent that contains the selected pixels. There is no point in working with an overly-large image if all we are interested in are the pixels that comprise Afghanistan.
In the Transform toolbar , use the Crop operator on the selected pixels and press Apply.
We can see we have cut out the rectangular region of pixels containing Afghanistan from the much larger original image. The image is now only 328 pixels by 208 pixels and so requires far less size to store. The smaller image will also allow faster system performance.
We now delete all pixels outside of Afghanistan. Choose Edit - Select Inverse to select all pixels outside of Afghanistan.
Choose Edit - Delete to delete these pixels. The background appears white because we are viewing a map that has a default background of white (see the Layers pane topic). If we switched off the background we could see that the image consists of the pixels within Afghanistan and invisible pixels.
In images, "deleting" a pixel turns it into an invisible pixel. Note from the Invisible Pixels topic that invisible pixels are still there even though they cannot be seen.
If we turn on the Countries layer once more we can see that the only visible pixels in the image are those in Afghanistan. In the illustration above we have renamed the image Afghanistan.
Now would be a good time to save this .map file so that in the future we could import the image whenever we need a georegistered image of Afghanistan. We could use that image by itself to create cool new maps or we could use it with other images and drawings for special effects.
For example, the above map was created by showing the cropped Afghanistan image in a map above the Countries drawing and a lower layer using the original image. The lower image layer is shown with 40% opacity to make it less vivid than the Afghanistan image. In addition, a drop shadow created using Gaussian Blur was added below the Afghanistan image.
Step 5: Create a drop shadow (for advanced users)
Drop shadows are frequently used to provide a "floating" effect as though some parts of a map are floating above other parts. The following description is not central to the main theme of this Example (the theme is using Transfer Selection to crop images to match desired areas in drawings) but for advanced users it shows how to create a drop shadow. As this section is intended for advanced users, the descriptions assume greater familiarity with Manifold System.
Copy the Afghanistan image and paste it as a new image. Rename the new image Shadow. Open the image in an image window.
Use Add Margin in the transform toolbar to add 50 pixels of margin. We will need the extra margin to make a drop shadow since the image was cropped right to the edge of Afghanistan.
Using Touch Select, click on the black margin to select it. Press Delete to "delete" it (that is, turn it into invisible pixels).
We now have the same image but with a larger margin of invisible pixels around Afghanistan. We will color the invisible pixels white and the Afghanistan pixels black.
Use Image - Adjust - Hue / Saturation and move the Lightness slider all the way to zero to make the Afghanistan pixels black. The invisible pixels are unaffected by the Lightness slider.
In the format toolbar make sure the foreground color is white and then use SHIFT - Paint Bucket to click anywhere in the region of invisible pixels to color them white. The SHIFT key will cause the white color to fill all invisible pixels anywhere in the image.
Use Gaussian Blur to blur the image by 10 pixels. So far, so good, except that we don't want a white background, we want a transparent background. This is accomplished using a mask to change the alpha channel transparency in the Shadow image.
Copy the Shadow image and paste it as a new image. Rename that image Mask.
Open the Mask image and use Image - Convert To to change the mask image into a Grayscale image. Only grayscale images can be used as masks. Close the Mask image and click on the Shadow image again to make it the active window.
Use the Edit - Load Mask/Channel command to load the Mask image into the alpha channel of the Shadow image.
The final result is a Shadow image that is a Gaussian drop shadow of the original Afghanistan pixel region. The amazing thing about Manifold as opposed to ordinary graphics editors is that this image is still georegistered to the original Afghanistan image. After all, it was pasted from the original, georegistered image and so was georegistered when it was pasted. Manifold maintained its georegistration throughout the entire sequence of image editing commands that were applied.
To use this drop shadow, we drag and drop it into our map underneath the Afghanistan image. The shadow appears immediately underneath the Afghanistan image, but to give a convincing optical effect to fool the eye we should offset the shadow slightly lower and to the right.
To do this we right click on the Shadow layer tab and choose Register. In the Register dialog we can change the Local offset in X and Y to displace the drop shadow downward and to the right so that it is partially visible underneath the Afghanistan layer. We increased the X value slightly and decreased the Y value slightly, the exact changes being found by trying different values with the Preview box checked.
As seen together with the Countries drawing layer and the Afghanistan image layer the Shadow layer gives a convincing impression of a drop shadow. Note that because the Shadow layer employs alpha channel transparency, it will correctly allow any other layer beneath it to show through in a convincing manner.
For example we can add a copy of the original image layer underneath all other layers and se the opacity of the background image layer to 40% to de-emphasize it. (We can get this copy of the original image layer by importing it from the .map project saved earlier in this example.) We can also add a labels component. Finally, we can move the Countries layer below the Afghanistan image so that the image would not be ringed with a black boundary line, and we can lower the opacity of the Countries layer so that the black border line is also de-emphasized.
The completed map is seen above.
Drop shadows created in the above manner are remarkable things in that they show correct transparency as regards any layers below them. If other drawing layers (such as railroads or hydrography) were turned on underneath the Afghanistan and Shadow layers, the drop shadow would correctly drape over any drawing objects passing underneath the shadow just as shadows do in real life.
How is it that we could use the Shadow image as a mask to specify transparency? This is a fortunate coincidence in that the transparency of an alpha channel is set by the range from black (no transparency) to white (full transparency) that exactly coincides with the grayscale range of the Shadow image. Using the Shadow image in grayscale form as its own alpha channel mask gives us the transparency we want in the drop shadow.
The detail-oriented reader will note that creating a margin of 50 extra pixels results in a slightly larger image than necessary for the Shadow image. After all, we need only those pixels that extend to the edge of the darker pixels created by the Gaussian Blur yet using the procedure above we are creating a Shadow image that is slightly larger than necessary because it involves invisible pixels beyond the reach of the shadow effect.
We could have arranged for a smaller image by using the Crop command on the Shadow image. After doing the blur, we could have selected a rectangular section of pixels in the Shadow image that extended just past the darker pixels created by the Gaussian Blur command and then cropped the Shadow image to that rectangular section. This is not such a big deal with such a small image, but it is a fine point of detail that might bear attention in the case of much larger images.