# 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.

https://www.metabunk.org/delog/?img...org/delog/herdon-v-NASA-0.1-30.jpg&a=0.1&b=30

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.
Code:
``````// 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
ctx.drawImage(
img,
0, srcY, img.width, 1,
0, line, canvas.width, 1);
}``````

Feel free to reuse this code

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