[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [digikam/development/gsoc2013-imgqsort] tests/imgqsort: Added basic compression detection method
From:       Gowtham Ashok <gwty93 () gmail ! com>
Date:       2013-08-01 1:47:24
Message-ID: E1V4hzA-0006rv-D0 () scm ! kde ! org
[Download RAW message or body]

Git commit 8980a6f93c748b68a7e95df975f10161638bca8d by Gowtham Ashok.
Committed on 01/08/2013 at 01:46.
Pushed by gowthamashok into branch 'development/gsoc2013-imgqsort'.

Added basic compression detection method

A  +5    -0    tests/imgqsort/detectcompression/CMakeLists.txt
A  +184  -0    tests/imgqsort/detectcompression/detectcompression.cpp     [License: \
GPL (v2+)] M  +1    -1    tests/imgqsort/detectnoise/CMakeLists.txt

http://commits.kde.org/digikam/8980a6f93c748b68a7e95df975f10161638bca8d

diff --git a/tests/imgqsort/detectcompression/CMakeLists.txt \
b/tests/imgqsort/detectcompression/CMakeLists.txt new file mode 100644
index 0000000..73ba98d
--- /dev/null
+++ b/tests/imgqsort/detectcompression/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8)
+project( DetectCompression )
+find_package( OpenCV REQUIRED )
+add_executable( detectcompression detectcompression.cpp )
+target_link_libraries( detectcompression ${OpenCV_LIBS} )
diff --git a/tests/imgqsort/detectcompression/detectcompression.cpp \
b/tests/imgqsort/detectcompression/detectcompression.cpp new file mode 100644
index 0000000..8cea77a
--- /dev/null
+++ b/tests/imgqsort/detectcompression/detectcompression.cpp
@@ -0,0 +1,184 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date        :
+ * Description : Detects compression by analyzing the intensity of blocks
+ *
+ * Copyright (C) 2013-2014 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2013-2014 by Gowtham Ashok <gwty93 at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include <stdlib.h>
+#include <stdio.h>
+#include <iostream>
+
+using namespace cv;
+using namespace std;
+
+// Global variable
+Mat src, src_gray;
+#define block_size 8
+
+//TODO: should calibrate the THRESHOLD value
+#define THRESHOLD 147
+
+
+/* @function main */
+int main( int argc, char** argv )
+{
+    int i;
+    int count=8;
+    int countblocks=0;
+    int number_of_blocks=0;
+    int sum=0;
+    vector<int> average_bottom,average_middle,average_top;
+    // Load an image
+    src = imread( argv[1] );
+
+    if ( !src.data )
+    {
+        return -1;
+    }
+
+    // Convert the image to grayscale
+    cvtColor( src, src_gray, CV_BGR2GRAY );
+
+    //go through 8 blocks at a time horizontally
+    //iterating through columns
+    for (int i = 0; i < src_gray.rows; i++)
+    {
+        //calculating intensity of top column
+        for (int j = 0; j < src_gray.cols; j+=8)
+        {
+            sum=0;
+
+            for (int k=j; k<block_size; k++)
+            {
+                sum += (int)src_gray.at<uchar>(i, j);
+            }
+
+            average_top.push_back(sum/8);
+        }
+
+        //calculating intensity of middle column
+        for (int j = 0; j < src_gray.cols; j+=8)
+        {
+            sum=0;
+
+            for (int k=j; k<block_size; k++)
+            {
+                sum += (int)src_gray.at<uchar>(i+1, j);
+            }
+
+            average_middle.push_back(sum/8);
+        }
+
+        //calculating intensity of bottom column
+        countblocks=0;
+
+        for (int j = 0; j < src_gray.cols; j+=8)
+        {
+            sum=0;
+
+            for (int k=j; k<block_size; k++)
+            {
+                sum += (int)src_gray.at<uchar>(i+2, j);
+            }
+            average_bottom.push_back(sum/8);
+            countblocks++;
+        }
+
+        //check if the average intensity of 8 blocks in the top, middle and bottom \
rows are equal. If so increment number_of_blocks +        for (int j=0; \
j<countblocks; j++) +        {
+            if ((average_middle[j]==(average_top[j]+average_bottom[j])/2) && \
average_middle[j]>THRESHOLD) +            {
+                number_of_blocks++;
+            }
+        }
+
+    }
+
+    average_bottom.clear();
+    average_middle.clear();
+    average_top.clear();
+
+    //iterating through rows
+
+    for (int j= 0; j < src_gray.cols; j++)
+    {
+        //calculating intensity of top row
+        for (int i = 0; i< src_gray.rows; i+=8)
+        {
+            sum=0;
+
+            for (int k=i; k<block_size; k++)
+            {
+                sum += (int)src_gray.at<uchar>(i, j);
+            }
+
+            average_top.push_back(sum/8);
+        }
+
+        //calculating intensity of middle row
+        for (int i= 0; i< src_gray.rows; i+=8)
+        {
+            sum=0;
+
+            for (int k=i; k<block_size; k++)
+            {
+                sum += (int)src_gray.at<uchar>(i, j+1);
+            }
+
+            average_middle.push_back(sum/8);
+        }
+
+        //calculating intensity of bottom row
+        countblocks=0;
+
+        for (int i = 0; i< src_gray.rows; i+=8)
+        {
+            sum=0;
+
+            for (int k=i; k<block_size; k++)
+            {
+                sum += (int)src_gray.at<uchar>(i, j+2);
+            }
+
+            average_bottom.push_back(sum/8);
+            countblocks++;
+        }
+
+        //check if the average intensity of 8 blocks in the top, middle and bottom \
rows are equal. If so increment number_of_blocks +        for (int i=0; \
i<countblocks; i++) +        {
+            if ((average_middle[i]==(average_top[i]+average_bottom[i])/2) && \
average_middle[i]>THRESHOLD) +            {
+                number_of_blocks++;
+            }
+        }
+
+    }
+
+    std::cout<<"Number of blocks: "<<number_of_blocks<<"\t\t";
+    //we can set the threshold value, after testing, as to how many blocks make a \
picture blocky[ be affected by JPEG Compression] +    waitKey(0);
+
+    return 0;
+}
diff --git a/tests/imgqsort/detectnoise/CMakeLists.txt \
b/tests/imgqsort/detectnoise/CMakeLists.txt index 72f3315..18ead8a 100644
--- a/tests/imgqsort/detectnoise/CMakeLists.txt
+++ b/tests/imgqsort/detectnoise/CMakeLists.txt
@@ -2,4 +2,4 @@ cmake_minimum_required(VERSION 2.8)
 project( DisplayImage )
 find_package( OpenCV REQUIRED )
 add_executable( detectnoise detectnoise.cpp )
-target_link_libraries( detectnoise ${OpenCV_LIBS} )
+target_link_libraries( detectblur ${OpenCV_LIBS} )


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic