blur-detection icon indicating copy to clipboard operation
blur-detection copied to clipboard

Support for other Image Formats / Opencv - Discussion Issue

Open saurabheights opened this issue 8 years ago • 5 comments

Hi tokenrove, Hope you are doing good. This is not much of an issue, but for discussion. As mentioned earlier, I have recently ported IIR technique for local block metrics computation to Opencv. This should allow testing on any image format already supported in Opencv(which I am assuming are almost all we see in our daily life).

The problem is implementing other techniques like computing

  1. Sharpness via DCT coefficients, and
  2. Sharpness via Wavelet-based Edge Detector.

The problem is computing DCT. Opencv AFAIK, doesn't provide api for extracting DCT coefficients from Image directly. One has to do DCT of decoded image(even if it was jpeg). Will this be an issue?

On side note: Meanwhile, having test suite will definitely help. I wouldn't have been able to notice the earlier bug without my test image. Please, no hurries on my part. My changes should also resolve your thoughts on making it work on stream of images.

Best Regards.

saurabheights avatar Jun 25 '16 23:06 saurabheights

Hi tokenrove, My apologies for the long delay in reply. Have been heavily busy with few exams and office work since last August.

I worked on this issue and used OpenCV to support all Image types which was necessary for our project. While doing so, I redesigned the code for easy readability. The only issue is since we use OpenCV, I completed the code only for IIR Filter. Supporting other two strategies would require more work and may not be possible with OpenCV only.

Albeit, the changes made for improving the code readability really made a difference. So I propose to first apply these changes. If you like the thoughts, I can apply those changes to your original code without removing other strategies. In case if any change is objectionable, do let me know.

Change 1: Moved to C++. OOPs make a good difference in readability. I am not aware of how much it might affect the execution speed. Something you can comment on.

Change 2: Restructure as follows:- Directory Structure:- . ├── include │   ├── BlockMetricsCalculator.h // Abstract class of local metrics calculator. (BMC) │   ├── BlockMetricsCalculatorIIR.h // IIR implementation │   ├── DistanceUtils.h // Stores manhattan_distance related methods │   ├── GlobalMetricsCalculator.h // The name should suffice for its meaning(GMC) │   ├── ImageBlurDetector.h // The top layer class which encapsulates BMC and GMC. │   ├── ImageData.h // Stores all data - input image, intermediate processing resuts, final output │   ├── ImageUtils.h // For any additional helper methods │   └── config.h // For configuration. ├── makefile └── src ├── BlockMetricsCalculatorIIR.cpp ├── GlobalMetricsCalculator.cpp ├── ImageBlurDetector.cpp ├── ImageData.cpp ├── ImageUtils.cpp └── main.cpp

Some more info: -

main.cpp: creates ImageBlurDetector class object, parses options and sets their value in config.h. Finally, it calls ImageBlurDetector to compute sharpness.

ImageBlurDetector:- Stores current strategy type(enum StrategyType { IIR_FILTER, TONG_LI_ZHANG_ZHANG, MARICHAL_MA_ZHANG }; in config.h), creates corresponding LocalBlurDetector object for the strategy and GlobalBlurDetector.

GlobalBlurDetector: Concrete class to compute Image Global metrics by reading data from ImageData object and making decisions.

BlockMetricsCalculator: - An abstract class which has a method computeLocalMetrics. This method takes an ImageData object, computes Local Sharpness Information and stores it back in ImageData.

BlockMetricsCalculatorIIR: - Concrete implementation of BlockMetricsCalculator for IIR method.

ImageData:- // Stores Image specific data in ImageData class, such as Mat(opencv holder for image) and additional objects of related classes such as - RuleOfThird, FiguresOfMerit, BlockMetrics class. I stored all these other classes in ImageData but they can be in their own separate files.

+Whole Lotta Love, err, I mean comments. I'm pretty sure any newbie would love these changes, but heavy reduction in the speed might not be well taken by users.

saurabheights avatar Jun 02 '17 12:06 saurabheights

Thanks for all the thoughtful comments!

I think that if you are considering porting the code to C++, you should fork this project. You have my blessing to do so, but I will not be maintaining this code in C++.

I actually did give a thought to porting this code to Rust, though, which I feel would be a better option going forward. (Also, the last time you poked me about this project, I made some plans for refactoring the code into a useful command-line utility, but never got back to it.)

I might get around to doing that at some point, but in the mean time, I think it's always whoever's writing code can write the rules. If you do fork and the project reaches a better level of maturity, I would be happy to update the README on this project to point newcomers to your fork. (which shouldn't be hard; as you know, this is a piece of code extracted from a project I worked on years ago (at least 7 years ago, I think), and although I appreciate the continuing interest in it I haven't been very active in doing much with it).

tokenrove avatar Jun 02 '17 19:06 tokenrove

Hi tokenrove, C++ is not a necessary option for me. I can ignore it and opt for struct(closest brother to classes). Most of the work is done from my end, and some effort would be needed only in adhering to C and making commits of atomic logical changes for easy PR. If you don't mind, I can give a small PR with a few commits to start. If you think the improvements are worth it, I can go ahead with that. Otherwise, forking would do. Both options require equivalent effort, but the only downside is ending up with two parallel repositories and would require double maintenance down the road. Please let me know whichever option you find more appropriate and I can take that turn.

Just my 2 cents, but such improvement on this project can very well smoothen the way for others with similar interests to dive in this work.

P.S. - Thanks for the "Rush" comment. It looks like a really good language.

saurabheights avatar Jun 02 '17 22:06 saurabheights

@saurabheights , Hi saurabheights, have you moved this repo to C++? I am instreated in opencv version.

zhcv avatar May 22 '18 16:05 zhcv

@zhcv - I had dropped in the middle as I left my job for MS. You can reach me, email id add at my page-bio. tokenrove - If you are reading this, apologies for unnecessary spam comment.

saurabheights avatar May 22 '18 21:05 saurabheights