Convert Graph Image from Log Scale to Linear Scale

Mick West

Staff member

Sometimes graphs are presented with a logarithmic vertical scale. This is useful for seeing the detail in the smaller range, but can give a misleading impression about how much a value is changing.

I wrote a no-frills tool to convert such images. It take as input a URL of a cropped portion of a graph and the bottom and top values of the y axis. For example.

Notice there how the red and black lines still drop down to just below 1, but now we can see on the larger scheme of things it's pretty much zero. The log scale made it look more significant. Also we can see the peak to the left (an artifact of stray light being magnified in software to account for decreasing sensitivity) is more polynomial than linear.

The code is relatively short, although the math was slightly headscratchy. I might extend it to drag-and-drop if needed. But this is an infrequently used tool.
// each line in the image of height h is k * previous line larger, where k is something like 1.02343
// we have start * k^h = end
// so k^h = end/start
// ln(k)*h = ln(end/start)
// k = exp(ln(end/start))/h

var h = img.height;
var k = Math.exp(Math.log(end / start) / (h))
console.log("n=" + n + ", k = " + k)

var n = canvas.height;  // n = number of lines

var log_pos = start;

// for each line in the canvas
for (var line = 0; line < n; ++line) {

	// v is value that goes 0 to 1 down the canvas
	var v = line / canvas.height;

	// convert that to a y value in the graph
	var y = start + (1 - v) * (end - start);

	// now convert that to a line number g in the log graph
	// we know y = start*k^g
	// so ln(y) = ln(start)+ln(k)*g
	// g = (ln(y) - ln(start))/ln(k)

	//				var srcY = img.height - (Math.log(y) - Math.log(start))/Math.log(k)
	// simplifies slightly as
	var srcY = h - (Math.log(y) - Math.log(start)) / (Math.log(end / start) / (h))

	// clamp srcY to be inside the image
	srcY = Math.max(0, Math.min(img.height - 1, srcY));

	// draw a single line from the src to the canvas
		0, srcY, img.width, 1,
		0, line, canvas.width, 1);

Feel free to reuse this code
Thread starter Related Articles Forum Replies Date
Alienentity Debunked: DSC graph of epoxy wouldn't look like DSC of red/gray chips 9/11 2
TopBunk UFO image collection issues UFOs and Aliens 26
Z.W. Wolf President Trump's Facial Changes After His Coronavirus Diagnosis. [AI upscaled image] Coronavirus COVID-19 25
D Mecca, center of land masses? Science and Pseudoscience 7
L Claim: NASA is doctoring an image [Scanner Dirt] UFOs and Aliens 7
L "Ghostly" image showing up on XBox Kinect 3D IR Scanner. Ghosts, Monsters, and the Paranormal 1
Mick West Debunked: Photo with Sun Rays at Odd Angles Flat Earth 0
Mechanik Plane Image on Google Maps in Cambodia - MH370 Speculation Flight MH370 10
Mick West A streak of light in a star trails image Skydentify - What is that Thing in the Sky? 2
Trailspotter Contrail cross over Tasmania and spinning contrails over Victoria Images and Videos: Contrails, Skies, and Aviation 0
StarGazer Claim: First Image of Space Taken from V-2 Rocket Proves the Earth is Flat Flat Earth 17
Mick West Zigzag contrail on Terra Image Skydentify - What is that Thing in the Sky? 4
Mick West Orbs with Dots - PDAF Focus Pixels in Sun Reflection Lens Flare Skydentify - What is that Thing in the Sky? 4
Mick West Eyes in a Cloud [Lens Flare + Panorama Stitching] Skydentify - What is that Thing in the Sky? 0
Trailblazer Identifying: faked image of Earth from space (artwork, not "official") Flat Earth 4
TEEJ Debunked: Hillary Clinton rally crowd image is photoshopped General Discussion 4
H Triangle in Mars Curiosity Image [Panorama Stitching Artifact] UFOs and Aliens 4
TEEJ Debunked: Image of Money Pallet shown in Iranian Documentary, 2016 General Discussion 1
Mick West Debunked: Cop Car Towed to Media Location then Torched at Million Mask March - BX10 LNV Conspiracy Theories 111
SR1419 Water Vapor loop Images and Videos: Contrails, Skies, and Aviation 2
Herman Aven Confirmed Claim: disputed satelite imagery showing "changes in vegetation" Flight MH17 14
Trailspotter Giant "distrail" across England Skydentify - What is that Thing in the Sky? 5
N Debunked: Nuclear cloud on Indian Mars Orbiter image Conspiracy Theories 29
Steve Funk Geoengineeringwatch uses photoshopped image Contrails and Chemtrails 7
Critical Thinker How to search for an image on Metabunk (and other websites) How To 9
J Debunked: Blurred NASA image on Mars [Stitched in part of the Rover] UFOs and Aliens 13
Steve Funk Geoengineering illustration [From New Scientist, 2009] Contrails and Chemtrails 11
Trailspotter The Blue Marble "super-contrail" Contrails and Chemtrails 15
Trailspotter Debunked: Crabzilla [Giant Crab Photoshopped into Bing Maps image] Ghosts, Monsters, and the Paranormal 19
Mick West How to create a Before/After image comparison with [Compare] Tags How To 0
Mick West History of a Fake BBC News 24 "Breaking News" image General Discussion 11
zebra100 Businessman Claims he Saw ‘White Plane Image’ Under Water while Flying from Melbourn Flight MH370 0
CapnPegleg Debunked: Photo of "Nessie" in Apple Maps Satellite image of Loch Ness [Boat] Science and Pseudoscience 16
TWCobra Australian and New Zealand Geo-engineering protest posts photoshopped image. Contrails and Chemtrails 1
Mick West MH370: Debunked: Tomnod image of plane in jungle Flight MH370 13
Pete Tar MH370: Debunked: Image of plane over Andaman Islands on Mapbox Map Flight MH370 36
Mick West Debunked: The "These are Chemtrails! You stupid zombies!" image Contrails and Chemtrails 2
MikeC Looking for a particular image - airliner contrail at takeoff Contrails and Chemtrails 9
Mick West How to upload and attach an image or file to a post How To 3
Jay Reynolds Image of Jet on Contrails and Chemtrails 3
Mick West Automatic Image Rehosting Site Feedback & News 1
Mick West How to Post an Image on Metabunk How To 5
Related Articles

Related Articles