imagediff

package module
v0.0.0-...-7cdf378 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2023 License: GPL-3.0 Imports: 9 Imported by: 1

README

Imagediff

Overview

ImageDiff is a Go package for comparing images and visually highlighting their differences. It is useful for tasks like automated testing, where verifying the correctness of image outputs is crucial. The package provides a straightforward API to compare two images, generating a third image that visually marks the differences.

Features

Compare two images and highlight differences. Supports different color coding for various levels of differences. Handles images of different sizes. Outputs a new image marking areas present in one image but not the other.

Installation

To install the command-line tool:

go install codeberg.org/slaxor/imagediff/cmd/imagediff@master

Usage

Import the package in your Go file:

import "codeberg.org/slaxor/imagediff"

Basic usage involves calling the CompareFiles function with the paths of the two images to compare and the output file path:

equal, err := imagediff.CompareFiles("path/to/image1.png", "path/to/image2.png", "path/to/result.png")
if err != nil {
    log.Fatalf("Error comparing images: %v", err)
}
if !equal {
    fmt.Println("Images are different, see image1_png_image2_png_diff.png for details.")
} else {
    fmt.Println("Images are identical.")
}

Command-Line Tool

After installation, you can use the imagediff command to compare images:

imagediff image1.png image2.png

If the images differ it will return a message telling you and save a file (image1_png_image2_png_diff.png in our case) marking the differences. You can use it as an overlay on your originals with any graphics program of your choosing.

As an example consider:

a image b image diffres ## Contributing

Contributions are welcome. Please open an issue or submit a pull request with your improvements.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Palette = color.Palette{
		palColors["sameColor"],
		palColors["diffColor1"],
		palColors["diffColor2"],
		palColors["diffColor3"],
		palColors["diffColor4"],
		palColors["diffColor5"],
		palColors["diffColor6"],
		palColors["diffColor7"],
		palColors["diffColor8"],
		palColors["aOnlyColor"],
		palColors["bOnlyColor"],
	}
)

Functions

func Compare

func Compare(a, b image.Image) (image.Image, bool, error)

Compare takes 2 imgs compares them and returns a result img the combined size of the 2 with all differences marked as 50% red and a only as 50% cyan b only as 50% orange a boolean telling if the imgs differ

func CompareFiles

func CompareFiles(aFile, bFile, resultFile string) (bool, error)

CompareFiles takes 2 input and an output filename as argument compares them and write the difference to the resultFile returns a bool telling if differences have been found and an error which we hope is nil.

func Merge

func Merge(images ...image.Image) image.Image

Types

This section is empty.

Directories

Path Synopsis
cmd
imagediff Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL