{"id":17965243,"url":"https://github.com/tokenrove/blur-detection","last_synced_at":"2025-03-25T06:31:13.658Z","repository":{"id":11597914,"uuid":"14089761","full_name":"tokenrove/blur-detection","owner":"tokenrove","description":"Some implementations of algorithms for blur detection in JPEGs","archived":false,"fork":false,"pushed_at":"2017-06-07T23:05:38.000Z","size":577,"stargazers_count":140,"open_issues_count":5,"forks_count":51,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-19T09:40:48.645Z","etag":null,"topics":["c","image-processing","jpeg"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tokenrove.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-03T17:36:16.000Z","updated_at":"2024-10-23T11:47:30.000Z","dependencies_parsed_at":"2022-09-24T01:01:00.805Z","dependency_job_id":null,"html_url":"https://github.com/tokenrove/blur-detection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenrove%2Fblur-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenrove%2Fblur-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenrove%2Fblur-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenrove%2Fblur-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tokenrove","download_url":"https://codeload.github.com/tokenrove/blur-detection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245413707,"owners_count":20611353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","image-processing","jpeg"],"created_at":"2024-10-29T12:10:37.211Z","updated_at":"2025-03-25T06:31:13.333Z","avatar_url":"https://github.com/tokenrove.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+OPTIONS: f:t\n\nThis comes from some work I did on a contract a few years ago.  While\nI obviously can't publish everything related to that work, I had\nretained the copyright to some of the low-level implementations\nexactly so that I could open source them later.\n\n(N.B.: This code is now explictly licensed, per the LICENSE file.)\n\nWhat follows are some notes I had written about a broader approach\nthat was built on this code.  I expect that research in this area has\nsince surpassed this approach.\n\n* Overview\n\nThis is an attempt to synthesize an algorithm for automatic ranking of\ndigital photographs, based on the following basic assumptions about\nquality:\n\n - good photos have the subject matter in focus;\n - the focal mass will generally lie close to the points defined by the rule of thirds;\n - the subject matter will also be separated from the background by brightness and saturation.\n\nWe note that the sharpness of a region is a reasonable predictor of\nfocus, as most prominent subject matter contains detailed edge\nstructures that are destroyed by out-of-focus/motion blur.\n\nAfter the description of the algorithm and the work on which it is\nbased, I discuss directions for improvement.\n\n* Review of Prior Work\n\nOur approach broadly builds upon the approach suggested by Lim, Yen,\nand Wu[fn:lim-yen-wu], though their goal is simply making a\ndecision as to whether an image is out-of-focus or not.\n\nA related set of ideas for determining the aesthetic value of an image\nis given by Liu et al.[fn:liu-et-al], but their focus is on\nreframing an existing image to capture the most aesthetic possible\ncropping of an image.\n\n* Description of the Algorithm\n\nGiven an image, we first decompose it into square blocks of pixels.\nWe have chosen 64x64 pixels rather than the arbitrary 100x100\nsuggested in [fn:lim-yen-wu] to facilitate the incorporation of\nDiscrete Cosine Transform (DCT) information in the common case that\nthe image is JPEG encoded.\n\n** Blockwise Metrics\n\nFor each block, we compute the hue, saturation, and intensity of each\npixel.  Note that it might be possible to speed up the algorithm here\nby skipping this computation and using only luminance values for\nblurred blocks.\n\nWe wish to make a boolean decision about whether this block is likely\nto be in focus, based on whether the sharpness of this block exceeds a\nthreshold.  In the present implementation, we have three different\nsharpness metrics.  We will describe each, as well as a proposed\nunification of the methods.\n\n** Sharpness via DCT coefficients\n\nIn the case that we have access to DCT information, we can perform a\nsimple histogram algorithm due to Marichal, Ma, and Zhang\n([fn:marichal-ma-zhang]).  For each 8x8 DCT block in this image\nblock, we count the occurance of coefficients greater than a minimum\nvalue in a histogram.  After each DCT block has been considered, we\ncompare each value in the histogram against the histogram value for\nthe first coefficient (0,0), summing a weighted value when the value\nexceeds a threshold.\n\nThis provides an extremely rapid approximation of blur extent.  In the\ncase that this value exceeds certain thresholds, it would be possible\nto skip further computation of more accurate sharpness metrics.\n\n** Sharpness via a Wavelet-based Edge Detector\n\nTong et al.[fn:tong-li-zhang-zhang] present an approach to blur\nestimation based on the Haar wavelet transform, whereby specific edge\nstructures can be detected, and the ratio of Dirac and abrupt-step\nstructures to roof and gradual step edge structures provides an\nacceptable estimation of the sharpness of the given block.\n\nIn our case, we have modified this algorithm to skip the windowing\nstep, as we felt that adjusting the thresholds by which a point was\nclassified was more effective than performing non-maximum suppression\n(NMS).\n\nUnfortunately, even without NMS, this is the most computationally\nexpensive of the algorithms implemented.\n\nIn his master's thesis [fn:ramakrishnan-thesis], Harish Ramakrishnan\npresents some variants on this approach and evaluates their\nperformance.\n\n** Sharpness via an IIR Filter\n\nShaked and Tastl[fn:shaked-tastl] derive a model of sharpness based\non the ratio between high-frequency data and low-frequency data, and\npresent an approach to computing this metric via a pair of\none-dimensional IIR filters.  The advantage of this decomposable\napproach is that rows or columns can be skipped to speed up the\nprocess at the cost of accuracy.\n\nPresently we use simple Butterworth high- and low-pass filters on row\nand column data to compute the sharpness metric.  However, it seems\nlikely that better filter designs could help improve the accuracy and\nperformance of this model.\n\n** Alternative Sharpness Measures\n\nA Canny edge detector could be used in much the same way as the Haar\ntransform approach given above.  It is possible that this could be\nmore efficient.\n\nAnother alternative, discussed in [fn:ramakrishnan-thesis], is the\nperceptual blur metric given by Marziliano et al. in\n[fn:marziliano-et-al].  We have thus far not considered using this\nblur metric as it seems less efficient than the methods we already\nimplement.\n\n** Combining Sharpness Metrics\n\nIn general, we avoid using the IIR filter in preference to the wavelet\ntransform approach or the DCT coefficient histogram.  Ideally, we\nwould use the fastest and least-accurate methods (DCT coefficients,\nIIR filter with a large row/column skip) to eliminate clearly blurry\nblocks, and then only use the more expensive wavelet transform\napproach on blocks whose sharpness isn't evident.\n\n** Other block-level metrics\n\nAlong with a sharpness value for each block, we also compute the means\nof the block's hue, intensity, and saturation values, as well as a\nratio of the number of pixels having a hue similar to that of blue sky\n(per [fn:lim-yen-wu]).\n\n** Global merits\n\nHaving computed these metrics for each block in the image, we compute\nseveral global indicators of quality.  Blocks whose dominant hue is\nthat of blue sky are ignored during this process.\n\nWe compute a composition score as a sum of the blocks which are sharp,\nweighted by the Manhattan distance of the block from one of the four\n``power points'' representing intersections of the division of the\nimage in thirds, as per the rule of thirds.\n\nWe compute brightness and saturation indices as the difference between\nthe mean of those values for blocks considered sharp and the mean of\nthose values for the remaining blocks.\n\nWe also compute the density of sharp blocks, as the ratio of sharp\nblocks to unsharp ones, and the median block sharpness.\n\n** Weighted ranking\n\nThis is where work needs to proceed: improving the quality of indices\nother than composition so they can be combined with appropriate\nweights to produce a single ranking value.\n\nPresently we can provide a ranking based on Lim et al.'s process for\ndeciding if an image is in focus: compute the sum of composition,\nbrightness, and saturation weighted by density and median sharpness,\nas well as individual weights prioritizing composition over brightness\nand saturation.\n\n* Directions for Further Work\n\nThe composition weighting could be improved in a number of ways.\nPerhaps the Manhattan distance from a power point is insufficient, and\na more sophisticated model of the rule of thirds is required.  Another\npossible direction is incorporating the idea of balanced masses as\ndiscussed in [fn:liu-et-al]; note that within our presented\napproach, we could simplify that scheme by considering each block a\nunit of mass based on its sharpness value.\n\nLim et al.'s sky hue ratio is questionable and it remains to be seen\nif it is indeed an effective metric for our purposes.\n\n* References\n\n[fn:lim-yen-wu] Suk Hwan Lim, Jonathan Yen, Peng Wu,\n  [[http://www.hpl.hp.com/techreports/2005/HPL-2005-14.html][*Detection of Out-Of-Focus Digital Photographs*]],\n  HPL-2005-14,\n  2005.\n\n[fn:tong-li-zhang-zhang] Hanghang Tong, Mingjing Li, Hongjiang Zhang, Changshui Zhang,\n  [[http://cs.cmu.edu/~htong/pdf/ICME04_tong.pdf%E2%80%8E%0A][*Blur detection for digital images using wavelet transform*]],\n  Proceedings of the IEEE International Conference on Multimedia \u0026 Expo,\n  2004.\n\n[fn:marichal-ma-zhang] Xavier Marichal, Wei-Ying Ma, Hongjiang Zhang,\n  [[http://research.microsoft.com/apps/pubs/default.aspx?id%3D68802][*Blur determination in the compressed domain using DCT information*]],\n  Proceedings of the IEEE ICIP, pp.386-390,\n  1999.\n\n[fn:liu-et-al] Ligang Liu, Renjie Chen, Lior Wolf, Daniel Cohen-Or,\n  [[http://www.math.zju.edu.cn/ligangliu/CAGD/Projects/Composition/paper/Composition-TR-low.pdf][*Optimizing Photo Composition*]],\n  Computer Graphics Forum, 29: 469-478,\n  2010.\n\n[fn:ramakrishnan-thesis] Harish Ramakrishnan,\n  [[https://mospace.library.umsystem.edu/xmlui/bitstream/handle/10355/27889/NarayananRamakrishnan_2010.pdf?sequence%3D1][*Detection and Estimation of Image Blur*]],\n  Master's Thesis,\n  2010.\n\n[fn:shaked-tastl] Dored Shaked, Ingeborg Tastl,\n  [[http://www.hpl.hp.com/techreports/2004/HPL-2004-84R2.pdf%E2%80%8E][*Sharpness Measure: Towards Automatic Image Enhancement*]],\n  HPL-2004-84,\n  2004.\n\n[fn:marziliano-et-al] Marziliano, P.; Dufaux, F.; Winkler, S.; Ebrahimi, T;\n  [[http://stefan.winklerbros.net/Publications/icip2002.pdf][*A no-reference perceptual blur metric*]],\n  Proceedings of International Conference on Image Processing,\n  2002.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokenrove%2Fblur-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftokenrove%2Fblur-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokenrove%2Fblur-detection/lists"}