Check blur radius

This commit is contained in:
esimov
2018-04-19 18:19:43 +03:00
parent cee4ec1d99
commit faae553275

16
main.go
View File

@@ -144,10 +144,12 @@ func process(input image.Image, done chan struct{}) bool {
draw.Draw(output, image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy()), img, image.ZP, draw.Src) draw.Draw(output, image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy()), img, image.ZP, draw.Src)
// Blur the image to eliminate the details. // Blur the image to eliminate the details.
blurImg := StackBlur(img, uint32(*blurRadius)) if *blurRadius > 0 {
img = StackBlur(img, uint32(*blurRadius))
}
// Convert image to YUV color space // Convert image to YUV color space
yuv := convertRGBImageToYUV(blurImg) yuv := convertRGBImageToYUV(img)
newImg := image.NewRGBA(yuv.Bounds()) newImg := image.NewRGBA(yuv.Bounds())
draw.Draw(newImg, image.Rect(0, 0, yuv.Bounds().Dx(), yuv.Bounds().Dy()), yuv, image.ZP, draw.Src) draw.Draw(newImg, image.Rect(0, 0, yuv.Bounds().Dx(), yuv.Bounds().Dy()), yuv, image.ZP, draw.Src)
@@ -182,7 +184,7 @@ func process(input image.Image, done chan struct{}) bool {
for i := i0; i < i1; i += 4 { for i := i0; i < i1; i += 4 {
// Get the YUV converted image pixels // Get the YUV converted image pixels
yc, uc, vc, _ := b.Pix[i+0], b.Pix[i+2], b.Pix[i+2], b.Pix[i+3] yc, uc, vc, _ := b.Pix[i+0], b.Pix[i+2], b.Pix[i+2], b.Pix[i+3]
// Convert YUV to RGB and obtain the R value // Convert YUV to RGB and obtain the R,G,B value
r, g, b := color.YCbCrToRGB(yc, uc, vc) r, g, b := color.YCbCrToRGB(yc, uc, vc)
for x := 0; x < *blockSize; x++ { for x := 0; x < *blockSize; x++ {
@@ -248,7 +250,7 @@ func process(input image.Image, done chan struct{}) bool {
// Lexicographically sort the feature vectors // Lexicographically sort the feature vectors
sort.Sort(featVec(features)) sort.Sort(featVec(features))
bar = pb.StartNew(len(features)-1) bar = pb.StartNew(len(features) - 1)
bar.Prefix("Analyze: ") bar.Prefix("Analyze: ")
for i := 0; i < len(features)-1; i++ { for i := 0; i < len(features)-1; i++ {
@@ -268,6 +270,7 @@ func process(input image.Image, done chan struct{}) bool {
forgedImg := image.NewRGBA(img.Bounds()) forgedImg := image.NewRGBA(img.Bounds())
overlay := color.RGBA{255, 0, 0, 255} overlay := color.RGBA{255, 0, 0, 255}
fmt.Println("Number of forged blocks detected: ", len(forgedBlocks))
for _, bl := range forgedBlocks { for _, bl := range forgedBlocks {
draw.Draw(forgedImg, image.Rect(bl.xa, bl.ya, bl.xa+*blockSize*2, bl.ya+*blockSize*2), &image.Uniform{overlay}, image.ZP, draw.Over) draw.Draw(forgedImg, image.Rect(bl.xa, bl.ya, bl.xa+*blockSize*2, bl.ya+*blockSize*2), &image.Uniform{overlay}, image.ZP, draw.Over)
} }
@@ -284,7 +287,7 @@ func process(input image.Image, done chan struct{}) bool {
fmt.Printf("Error encoding image file: %v", err) fmt.Printf("Error encoding image file: %v", err)
} }
done <- struct {}{} done <- struct{}{}
return result return result
} }
@@ -377,8 +380,6 @@ func filterOutNeighbors(vect []vector) (newVector, bool) {
for i := 1; i < len(vect); i++ { for i := 1; i < len(vect); i++ {
blockA, blockB := vect[i-1], vect[i] blockA, blockB := vect[i-1], vect[i]
// Continue only if two regions are not neighbors.
if blockA.xa != blockB.xa && blockA.ya != blockB.ya {
// Calculate the euclidean distance between both regions. // Calculate the euclidean distance between both regions.
dx := float64(blockA.xa - blockB.xa) dx := float64(blockA.xa - blockB.xa)
dy := float64(blockA.ya - blockB.ya) dy := float64(blockA.ya - blockB.ya)
@@ -395,7 +396,6 @@ func filterOutNeighbors(vect []vector) (newVector, bool) {
isForged = true isForged = true
} }
} }
}
bar.Increment() bar.Increment()
} }
bar.Finish() bar.Finish()