In my post The Four or Five or Whatever Color Theorem in ArcGIS Pro I explored two methods to effectively calculate color classes in a polygon feature layer in such a way that not any feature shares the same color with its neighbors. When I finally ended up with two pretty neat solutions, I had to somehow select the color themselves! So, among the millions of possible color combinations I could have selected, I preferred to sample the colors from the original map I had been inspired from at the first place.
Then I remembered a Tweet I had made a couple of years ago, where with four screenshots I describe a rapid process to sample colors from that map. The process included the following steps:
- Open the Resample Raster Function,
- Resample the image to a significantly larger cell size,
- Add a polygon map note and select colors with the Eyedropper tool,
- Save each color to a style!
In this article I reconsider this short process and I explore a more complex approach to sample colors from a scanned old map.
So, in the following paragraphs I will firstly describe an image-filtering approach with Raster Functions, with which I generalize and homogenize the original map, in order to sample colors as accurately as possible. Then I go through the creative stuff which includes sampling colors with the eyedropper tool and saving them in a custom Style.
I have uploaded a Map Package for ArcGIS Pro on my ArcGIS Online account here with all the maps and data and tools and expressions that will be described, so feel free to download and use it under a CC BY-NC-SA 4.0 license.
Preparing the Map from the David Rumsey Map Collection
First things first. From the David Rumsey Map Collection (see Picture 1) I download the map in Extra Large size by clicking on the Export button at the top-right of the page. I then unzip the downloaded file and I save the map, which comes in .jpg format, somewhere in my local storage.
This is a map depicting England and Wales drawn in 1827 by Anthony Finley found in the David Rumsey Map Collection, as shown in Picture 1.
Then I open ArcGIS Pro and I add it to a new Map, which I rename to Sample, as shown in Picture 2.
The map from the David Rumsey Map Collection comes with no georeference, but for the purposes of this work this is okay. When I add it on the Map in Pro its top-left corner will be automatically placed on Null Island, the point of the Earth where both longitude and latitude equal zero.
The map also is being added in the Contents pane. As shown in Picture 2, I select it and I open the Raster Layer contextual tab, as well as the Symbology pane, where I select:
- Minimum – Maximum for the Stretch type at the Symbology pane,
- Cubic for Resampling Type and
- 1 for Gamma
These adjustments will render the map from the David Rumsey Map Collection in Pro exactly as it is when viewed online or from another image viewing software.
Image filtering with raster functions
Next, I select the Imagery contextual tab and I click on the Function Editor button located at the Analysis group. A new Raster Function Template opens, as shown in Picture 3.
I then click on the Raster Functions button, also located at the Analysis group to open the Raster Functions pane (Picture 3).
Within the new Raster Function Template I can drag layers from the Contents pane, as well as various functions from the Raster Functions pane and to create a linear geoprocessing process, similar to that of the Model Builder.
As shown in Picture 4, I drag the map layer from the Contents pane into the new Raster Function Template and then I add three times the Extract Bands function from the Raster Functions pane.
The map from the David Rumsey Map Collection is a three band RGB image, which means that it is comprised of three bands, one for each of the colors Red, Green and Blue. Thus, I extract each band to a separate virtual layer within the Raster Function Template.
Picture 4 shows the Parameters tab of the Extract Bands Properties dialog of the Extract Bands function, where I select:
- The name of the map for Raster (automatically filled when linked),
- Band IDs for Method and
- 1 for Combination (1 stands for Red, 2 for Green and 3 for Blue band).
I then click on the General tab of the same dialog, as shown in Picture 5, where:
- I write Extract Red Band for Name,
- I leave the Description field as it is (although I could write a more explanatory paragraph) and
- I select 8 Bit Unsigned for the Output Pixel Type.
I repeat the same process for all three bands and I click OK to close the dialog.
All the useful information about the map from the David Rumsey Map Collection can be found in its properties. As shown in Picture 6, I double-click on its name in the Raster Function Template to open its Raster Properties from where I can read:
- The number of its bands,
- the pixel type and
- the cell size in both dimensions X and Y, which in this case is 1.
I will slightly increase the cell size from 1 to 2, in order to start generalizing the map. For this I go through the Raster Functions pane and I find the Resample function, which I drag three times in the Raster Function Template, one for each band, as shown in Picture 7.
I then double-click on each Resample function within the Raster Function Template to open its Resample Properties, where:
- I select Nearest Neighbor for Resampling Type,
- 1 for Input Cellsize and
- 2 for Output Cellsize.
Next I will perform a series of successive focal or neighborhood statistics on each band, with which I will gradually generalize the map. So for each one of the three bands I add three times the Statistics function within the Raster Function Template, as shown in Picture 8.
For each one of the nine Statistics function I open the Statistics Properties dialog, where:
- I select Median for Statistics Type and
- For Number of Rows and Columns I select gradually 3, 5 and 7.
The numbers 3, 5 and 7 are the numbers of cells that comprise each time the neighborhood around the pixel and the Median statistic type calculates the median value of all the pixels within the neighborhood.
The Median type is basically a classic low-pass filter, widely known as Median filter, used for noise reduction in image filtering. All three numbers selected for the neighborhood are odd numbers, so the neighborhood will form a square embracing the pixel.
It is worthwhile to note that a similar sequence of the Statistics functions has also been described by John Nelson in his video How To Generalize Hillshade Without the Artifacts, where in less than three minutes he explains the whole logic of Raster Functions chaining in ArcGIS Pro.
Finally, I select the Composite Bands function from the Raster Functions pane and I drag it within the Raster Function Template, as shown in Picture 9. This function will combine the three split bands to reform the multiband image, which this time will be heavily generalized due to the Median statistics and the Resample function.
To push a little further the generalization I will add a fourth Statistics function chain this time applied to the Composite; again three Medians with 3, 5 and 7 cell neighborhoods, as shown in Picture 10.
The chain ends with adding one more time the Resample Function, which will resample the output raster so that its cell size will be 5 by 5, as shown in Picture 11.
In Picture 11 I also indicate how to save the Raster Function Template as a new custom Raster Function within the Raster Functions pane. I simply click on the Save As icon to open the Save As dialog, where:
- I write Generalize for Name (I could also write any other name),
- I select Project for Category and Sub-Category, to save the new custom Raster Function within the current project and
- I write a brief Description and a short paragraph at the Help field.
When I click OK at the Save As dialog the new custom Raster Function is being saved in the Raster Functions pane, under the Project tab, as shown in Picture 12.
The moment the new custom Raster Function is saved, I can run it like any other of the default system functions (listed under the System tab of the Raster Functions pane). So, I click on the Generalize icon to open the new Raster Function and I click on the Create New Layer button.
The Generalize function is being executed and it returns a new layer on the Contents pane with the name Generalize, which is a heavily generalized version of the initial map from the David Rumsey Map Collection, as shown in Picture 13.
Next, at the Contents pane I select the newly created raster and I open the Raster Layer contextual tab, where I select:
- Minimum – Maximum for the Stretch type at the Symbology pane,
- Cubic for Resampling Type and
- 1 for Gamma
These adjustments will render the newly created Generalize raster to look like the original map derived from the David Rumsey Map Collection, as shown in Picture 14.
Having both layers visible on the Contents pane, I select the Generalize raster and from the Raster Layer contextual tab I click on the Swipe tool, located in the Compare group. As shown in Picture 15, I can swipe the topmost layer to reveal the one underneath. That way I can investigate the Generalize raster layer and examine whether the raster functions chain actually returned a generalized/homogenized layer whose cells more or less have the same or nearly the same color with the original map.
For example, in Picture 16 I can see that the Generalize raster layer has certain cells that are very close in color (pink), which is also very close to the average of the colors of the cells of the unprocessed original map below.
In Picture 17 you can swipe by yourself and compare the two raster layers, the original map at the left and the Generalize one, processed with raster functions, at the right.
Create a new Style
Time for the fun part with ArcGIS Pro Styles!
I open the Catalog pane where I right-click on the Styles folder. As shown in Picture 18, a dialog opens from where I gradually select New > New Style to Create a style in the project.
I then navigate to the directory in my local storage where I want to save the new style, which I name The_Four_Color_Theorem, as shown in Picture 19. Of course, I could have given to it any other name.
The new style is added in the Styles folder in the Catalog pane, as shown in Picture 20.
Sample colors with the Eyedropper tool
In order to sample the colors from the raster layer, I need to have a polygon vector layer in the Contents pane, so from the Insert contextual tab I add a Polygon Map Notes layer, located at the Layer Templates group. The Polygon Map Notes layer is added in the Contents pane, as shown in Picture 21.
Then, I right-click on its symbol in the Contents pane to open the color selection palette, from where I click on the Eyedropper tool.
With the Eyedropper tool selected, I navigate the Map to find a place where the cells of the Generalize raster layer have very similar colors and I click on a representative cell. The color of that cell is added in the symbol of the Polygon Map Notes layer.
I right-click again on the symbol of the Polygon Map Notes layer to open once again its color selection palette, only this time I click on the Color Properties option, at the very bottom of the dialog. As shown in Picture 22, the Color Editor opens indicating the RGB values of the sampled color.
I click on the Save color to style button and the Save Color As dialog appears, where:
- I write Color 1 for Name,
- I leave the Category and Tags fields with their default values and
- I select the style I created in the previous step for Style from the dropdown list of available styles.
I then click the OK button and the color is being saved within the selected style.
I open the Catalog View and with my style selected I click on the Manage contextual tab to activate the Manage styles capabilities. At the colors section of the style I can see Color 1, I saved in the previous step, as shown in Picture 23.
I repeat the same process for all other colors of the original map and I end up with a representative five-color palette within my style, as shown in Picture 24.
Apply the colors
Once I have sampled all colors and saved them in the style, I can use them wherever I want in my project. As shown in Picture 25, I can create a new Discrete Color Scheme for a polygon feature layer which needs to be symbolized with five unique values, using the newly sampled and saved colors.
And if I don’t like the order with which the colors appear in the color scheme and eventually on the dataset, I can simply rearrange them in the color scheme by dragging the stops in the Color Scheme Editor (Picture 26).
As a final touch, I can sample the color of the basemap of the original map and apply it to the background color of the Map which depicts the polygon feature layer, as shown in Picture 27.
Epilogue
And this is the approach I normally follow to sample colors from an old map. I would be very happy to hear your opinion or any suggestions for improvement of the process.
I have uploaded a Map Package for ArcGIS Pro on my ArcGIS Online account here which includes all the maps and data and tools described in the previous paragraphs. Feel free to download it and use it under a CC BY-NC-SA 4.0 license.
Kindest regards from Crete, Greece.
Spiros