News:

:) Please keep your software updated for best results!

Main Menu

Image export option for CalcImage

Started by Julien, December 11, 2017, 01:34:29 PM

Previous topic - Next topic

Ben Buse

#15
Thanks JonF, that's good to know. And thanks for the files, together with the files in your other post. I'd have thought code only works if colors evenly spaced along color scale, if your simply stating color table a list of colors, which isn't quite true above. But now have plenty of color tables from R, from ImageJ, and from Python, and several good rainbow luts. (Interpolation between Irregularly spaced colors could be done using cdict in matplotlib in python, but don't feel currently inclined https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.LinearSegmentedColormap.html)

JonF

Quote from: Ben Buse on May 21, 2025, 02:58:22 PMI'd have thought code only works if colors evenly spaced along color scale, if your simply stating color table a list of colors, which isn't quite true above.

Ah, good point.
I've created a new .FC file for the rainbow2 colour palette where the colours are the same layout as the ones in Surfer - and I actually opened Surfer to check this time!



Unevenly spaced rainbow2 colour palette file attached below, and the contents of the file can be opened in notepad/text editor to show this:

False color description for MicroImage
 BEGIN Items
 Interpolate=1
 Item=          0           0     0
 Item=          28          28    16711680
 Item=          66          66    16776960
 Item=          124         124   39168
 Item=          150         150   65535
 Item=          204         204   255
 Item=          244         244   16777215
 Item=          255         255   16777215
 END Items

I mostly did this one by hand because it was more effort coding it in!
All you need to do is:
  • set interpolate to 1
  • convert the fractional values that Surfer gives you (e.g. 0.5999999..) and multiply that by 255, then take the integer value of what comes back (0.59*255 = ~150) and put that in the first two columns
  • convert the hexadecimal colour code (e.g. 0xff6600) to decimal - I used the col2rgb function in my R script described above, but there are plenty of websites that will do the same for you

JonF

Here's rainbow, too.

Also tested in Surfer to make sure it's the same  ;D



Ben Buse

That's nice and a great way of converting it

Ben Buse

#19
Very helpful, it makes it easy to write a generic conversion script to convert .clr to .fc

.clr file
ColorMap 1 1
  0 153 102 255
20  0  0 255
40  0 255  0
60 255 255  0
80 255 102  0
100 255  0  0

becomes .fc file
False color description for MicroImage
BEGIN Items
Interpolate=1
Item= 0 0 16737945
Item= 20 20 16711680
Item= 40 40 65280
Item= 60 60 65535
Item= 80 80 26367
Item= 100 100 255
END Items

Where code
import pandas as pd
import tkinter
import tkinter.filedialog
lutlocation = tkinter.filedialog.askopenfile(title="select surfer .clr file")
savelocation = tkinter.filedialog.asksaveasfilename(title="select save location")
df = pd.read_csv(lutlocation.name, skiprows=1, sep="\s+", header=None)
f = open(savelocation,"a")
f.write(" False color description for MicroImage"+"\n")
f.write(" BEGIN Items"+"\n")
f.write(" Interpolate=1"+"\n")
for x in range(0,len(df)):
    r = df.iat[x,1]
    g = df.iat[x,2]
    b = df.iat[x,3]
    rgbdecimal = b * 65536 + g * 256 +r
    f.write(" Item= "+str(df.iat[x,0])+" "+str(df.iat[x,0])+" "+str(rgbdecimal)+"\n")
f.write(" END Items")
f.close()

Or if instead of 0 to 100, recast it as 0 to 255

False color description for MicroImage
 BEGIN Items
 Interpolate=1
 Item= 0.0 0.0 16737945
 Item= 51.0 51.0 16711680
 Item= 102.0 102.0 65280
 Item= 153.0 153.0 65535
 Item= 204.0 204.0 26367
 Item= 255.0 255.0 255
 END Items

And
import pandas as pd
import tkinter
import tkinter.filedialog
lutlocation = tkinter.filedialog.askopenfile(title="select surfer .clr file")
savelocation = tkinter.filedialog.asksaveasfilename(title="select save location")
df = pd.read_csv(lutlocation.name, skiprows=1, sep="\s+", header=None)
f = open(savelocation,"a")
f.write(" False color description for MicroImage"+"\n")
f.write(" BEGIN Items"+"\n")
f.write(" Interpolate=1"+"\n")
for x in range(0,len(df)):
    r = df.iat[x,1]
    g = df.iat[x,2]
    b = df.iat[x,3]
    rgbdecimal = b * 65536 + g * 256 +r
    f.write(" Item= "+str(255*((df.iat[x,0])/100))+" "+str(255*((df.iat[x,0])/100))+" "+str(rgbdecimal)+"\n")
f.write(" END Items")
f.close()

Interestingly in the case of rainbow2 - interpolate in classify extract image works different than in surfer - giving a different appearance.

Because interpolate ignores the position number in .fc in classify extract image, and simply divides equally by the number of entries/rows in the order given.

So

False color description for MicroImage
 BEGIN Items
 Interpolate=1
 Item= 0 0 16737945
 Item= 10 10 255
 Item= 255 255 255
 END Items

gives the same appearance as

False color description for MicroImage
 BEGIN Items
 Interpolate=1
 Item= 0 0 16737945
 Item= 85 10 255
 Item= 255 255 255
 END Items

So to instead to avoid interpolation in classify extract image for non even spacing, the following does the interpolation in python matplotlib to convert surfer .clr to .fc, where the list of colours includes their position along the scale

import pandas as pd
import tkinter
import tkinter.filedialog
import matplotlib
lutlocation = tkinter.filedialog.askopenfile(title="select surfer .clr file")
savelocation = tkinter.filedialog.asksaveasfilename(title="select save location")
df = pd.read_csv(lutlocation.name, skiprows=1, sep="\s+", header=None)
f = open(savelocation,"a")
f.write(" False color description for MicroImage"+"\n")
f.write(" BEGIN Items"+"\n")
f.write(" Interpolate=0"+"\n")
storey = -1
testcolours=[]
#read clr file to generate color map using colours and their position along the scale
for x in range(0,(len(df)-0)):
    test=(df.iat[x,1]/255,df.iat[x,2]/255,df.iat[x,3]/255)
    test2=(df.iat[x,0]/100,test)
    testcolours.append(test2)
    #cmap=matplotlib.colors.LinearSegmentedColormap.from_list(name='testmap',colors=[(0,'red'),(1,'blue')],N=255)
    cmap=matplotlib.colors.LinearSegmentedColormap.from_list(name='testmap',colors=testcolours,N=255)
norm = matplotlib.colors.Normalize(vmin=0, vmax=255)
#write a file from 0 to 255 with color from colour map
for x in range(0,255):
    #cmap() returns rgba; [] specifies r or g or b or a; norm(x) is 0 to 255 given as 0 to 1 for color map
    r = cmap(norm(x))[0]
    g = cmap(norm(x))[1]
    b = cmap(norm(x))[2]
    #rgb are in range 0 to 1
    rgbdecimal = int(b*255) * 65536 + int(g*255) * 256 + int(r*255)
    f.write(" Item= "+str(x)+" "+str(x)+" "+str(rgbdecimal)+"\n")
f.write(" END Items")
f.close()

Ben Buse

#20
Here's rainbow and rainbow 2, and others in zip

John Donovan

The latest version of Probe for EPMA (v. 14.2.3) has a new version of the Classify Image Exporter (v.1.2.1) for exporting maps as images in the CalcImage software:



In the new version Mia fixed a couple of minor bugs and improved support for wide or tall aspect ratio maps, by adding a separate field for the Y axis increment, for example as seen here:



Having separate controls for the X and Y axes allows for better graphics especially when the maps are very tall or wide as seen here:

John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

Ben Buse

#22
Very nice, I'll have to give it a try. What controls the title font size?

Mia Kraft

Quote from: Ben Buse on July 10, 2025, 08:59:27 AMVery nice, I'll have to give it a try. What controls the title font size?

As it stands the font size is automatically sized and positioned based on the resolution and what I saw as similar to historical examples.

John Donovan

#24
Quote from: Ben Buse on July 10, 2025, 08:59:27 AMVery nice, I'll have to give it a try. What controls the title font size?

As Mia said, the Classify Image Exporter app auto sizes all text, but if you want more control over image fonts and sizes, you should use the Surfer output options:

https://smf.probesoftware.com/index.php?topic=55.msg509#msg509

Basically you output your maps using the Surfer script option, run the script BAS file, then locate the .SRF file for that export and open it in Surfer and manually edit your maps as desired.  Then export your images from Surfer.
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"