Anonymous user
Percentage difference between images: Difference between revisions
Percentage difference between images (view source)
Revision as of 19:25, 18 October 2017
, 6 years ago→{{header|Go}}: eliminate code duplication
(→{{header|Java}}: restructure code to be reusable) |
(→{{header|Go}}: eliminate code duplication) |
||
Line 512:
"image/jpeg"
"os"
"log"
"image"
)
func loadJpeg(filename string) (image.Image, error) {
func main() {▼
f, err := os.Open(
if err != nil {
return▼
}
defer f.Close()
if err != nil {
return▼
}
if f, err = os.Open("Lenna100.jpg"); err != nil {▼
return img, nil
fmt.Println(err)▼
}
func diff(a, b uint32) int64 {
▲ return int64(a - b)
}
}
▲func main() {
i50, err := loadJpeg("Lenna50.jpg")
if err != nil {
}
}
if i50.ColorModel() != i100.ColorModel() {
}
b := i50.Bounds()
if !b.Eq(i100.Bounds()) {
}
var sum int64
for y := b.Min.Y; y < b.Max.Y; y++ {
Line 550 ⟶ 563:
r1, g1, b1, _ := i50.At(x, y).RGBA()
r2, g2, b2, _ := i100.At(x, y).RGBA()
▲ if g1 > g2 {
}
}
nPixels := (b.Max.X - b.Min.X) * (b.Max.Y - b.Min.Y)
fmt.Printf("Image difference: %f%%\n",
|