Bilinear interpolation: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (→{{header|F#|F sharp}}: Regularize header markup to recommended on category page) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 13:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<
INCLUDE "H6:LOADPPM5.ACT"
Line 120:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Bilinear_interpolation.png Screenshot from Atari 8-bit computer]
=={{header|C}}==
<
typedef struct {
uint32_t *pixels;
Line 172:
putpixel(dst,x, y, result);
}
}</
=={{header|C sharp|C#}}==
{{trans|Java}}
Seems to have some artifacting in the output, but the image is at least recognizable.
<
using System.Drawing;
Line 227:
}
}
}</
=={{header|D}}==
This uses the module from the Grayscale Image task.
{{trans|C}}
<
/// Currently this accepts only a Grayscale image, for simplicity.
Line 280:
im.rescaleGray(0.3, 0.1).savePGM("lena_smaller.pgm");
im.rescaleGray(1.3, 1.8).savePGM("lena_larger.pgm");
}</
=={{header|F sharp|F#}}==
{{trans|C#}}
<
open System.Drawing
Line 330:
result.Save("Lenna100_larger.jpg")
0 // return an integer exit code</
=={{header|Go}}==
Line 337:
<code>[https://godoc.org/golang.org/x/image/draw#BiLinear draw.BiLinear]</code>
from the <code>golang.org/x/image/draw</code> pacakge).
<
import (
Line 429:
}
return err
}</
=={{header|J}}==
<syntaxhighlight lang=J>
Note 'FEA'
Here we develop a general method to generate isoparametric interpolants.
Line 494:
shape_functions =: COEFFICIENTS mp~ shape_function
interpolate =: mp shape_functions
</syntaxhighlight>
<pre>
Note 'demonstrate the interpolant with a saddle'
Line 513:
Let n mean shape function, C mean constants, i mean interpolant, and the three digits meaning dimensionality, number of corners, and (in base 36) the number of nodes we construct various linear and quadratic interpolants in 1, 2, and 3 dimensions as
<syntaxhighlight lang=J>
Note 'Some elemental information'
Line 609:
i38q =: mp (C38r mp~ n38r)
i38r =: mp (C38r mp~ n38r)
</syntaxhighlight>
=={{header|Java}}==
{{trans|Kotlin}}
<
import java.awt.image.BufferedImage;
import java.io.File;
Line 668:
ImageIO.write(image2, "jpg", lenna2);
}
}</
=={{header|Julia}}==
<
function enlarge(A::Matrix, factor::AbstractFloat)
Line 684:
Alarge = enlarge(A, 1.6);
save("data/lennaenlarged.jpg", Alarge)
</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|C}}
<
import java.io.File
Line 737:
val lenna2 = File("Lenna100_larger.jpg")
ImageIO.write(image2, "jpg", lenna2)
}</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{{out}}
Shows a downloaded image that is 60% enlarged.
Line 747:
{{trans|F#}}
{{libheader|imageman}}
<
func lerp(s, e, t: float): float =
Line 780:
let image = loadImage[ColorRGBU]("Lenna100.jpg")
let newImage = image.scale(1.6, 1.6)
newImage.saveJPEG("Lenna100_bilinear.jpg")</
=={{header|Perl}}==
<
use warnings;
Line 793:
my $image2 = $image->copyScaleInterpolated( 1.6*$width, 1.6*$height );
$image2->_file('color_wheel_interpolated.png');</
Compare offsite images: [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/color_wheel.png color_wheel.png] vs.
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/color_wheel_interpolated.png color_wheel_interpolated.png]
Line 800:
{{libheader|Phix/pGUI}}
Gui app with slider for between 2 and 200% scaling. Various bits of this code scavenged from C#/Go/Kotlin/Wikipedia.
<
include pGUI.e
Line 923:
IupMainLoop()
IupClose()</
=={{header|Python}}==
Line 929:
Of course, it is much faster to use PIL, Pillow or SciPy to resize an image than to rely on this code.
<
import numpy as np
from scipy.misc import imread, imshow
Line 975:
imshow(enlargedImg)
</syntaxhighlight>
=={{header|Racket}}==
This mimics the Wikipedia example.
<
(require images/flomap)
Line 1,000:
(λ (k x y)
(flomap-bilinear-ref
fm k (+ 1/2 (/ x 250)) (+ 1/2 (/ y 250))))))</
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang=raku
use v6;
Line 1,034:
fclose($fh1);
fclose($fh2);
</syntaxhighlight>
{{out}}
Line 1,043:
=={{header|Scala}}==
===Imperative solution===
<
import java.io.{File, IOException}
Line 1,101:
private def lerp(s: Float, e: Float, t: Float) = s + (e - s) * t
}</
=={{header|Sidef}}==
{{trans|C}}
<
func scale(img, scaleX, scaleY) {
Line 1,145:
var img = %O<Imager>.new(file => "input.png")
var out = scale(img, 1.6, 1.6)
out.write(file => "output.png")</
=={{header|Tcl}}==
Line 1,153:
The script below will show the computed image in a GUI frame, and present a button to save it.
<
package require Tk
Line 1,198:
pack [button .b -text "save" -command [list save $im]]
</syntaxhighlight>
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
Module Module1
Line 1,253:
End Sub
End Module</
=={{header|Wren}}==
Line 1,259:
{{libheader|DOME}}
Note that currently DOME's ImageData class can only save files to disk in .png format.
<
import "graphics" for Canvas, Color, ImageData
import "math" for Math
Line 1,324:
}
var Game = BilinearInterpolation.new("Lenna100.jpg", "Lenna100_larger.png", 1.6, 1.6)</
=={{header|Yabasic}}==
{{trans|Nim}}
<
// Adapted from Nim to Yabasic by Galileo, 01/2022
Line 1,379:
dot x, y
next
next</
=={{header|zkl}}==
Line 1,386:
Not fast enough to be called slow.
<
fcn blerp(c00,c10,c01,c11, tx,ty){ lerp(lerp(c00,c10,tx), lerp(c01,c11,tx),ty) }
fcn scale(src, scaleX,scaleY){
Line 1,406:
}
dst
}</
<
img2:=scale(img,1.5,1.5);
img2.write(File("lena1.5.ppm","wb"));
scale(img,0.5,0.5).write(File("lena.5.ppm","wb"));</
{{out}}
http://www.zenkinetic.com/Images/RosettaCode/3Lenas.jpg
|