Ejemplo n.º 1
0
func findAmountOfPurpleInImage(imageFile *os.File) (int, error) {
	img, _, err := image.Decode(imageFile)
	if err != nil {
		return -1, err
	}
	img = turnGreyIntoWhite(img)
	//logImage(img);
	dominantColor := dominantcolor.Find(img)
	distanceToPurple := coloralgorithms.DistanceBetweenColors(dominantColor, purple)

	// The distance should be as small as possible, but the rank should be as high as possible
	rank := int(coloralgorithms.MAX_DISTANCE - distanceToPurple)
	return rank, nil
}
Ejemplo n.º 2
0
func findAmountOfPurpleInImagee(imageFile *os.File) (int, error) {
	image, error := fileToImage(imageFile)
	if error != nil {
		return 0, error
	}

	points := pixelsToPoints(image)
	dominantColors, error := coloralgorithms.FindClusters(config, points)
	if error != nil {
		return 0, error
	}

	clusterQualities := coloralgorithms.CalculateClusterQuality(config, dominantColors)
	index, _ := coloralgorithms.LaMaximum(clusterQualities, int(float64(len(points))*percentageOfPixelsPerCluster))
	if index < 0 {
		return -1, nil //errors.New("No cluster was large enough")
	}
	dominantColor := dominantColors[index]
	distanceToPurple := coloralgorithms.DistanceBetweenColors(pointToColor(*dominantColor.Center), purple)

	// The distance should be as small as possible, but the rank should be as high as possible
	rank := int(coloralgorithms.MAX_DISTANCE - distanceToPurple)
	return rank, nil
}