Ste*_*ing 1 c++ opencv image-processing computer-vision
我想检测是否有渐晕的图片,但找不到测量它的方法。我通过“渐晕指标、渐晕检测、渐晕分类”等关键字进行搜索,它们都会引导我找到“创建渐晕滤镜”或“渐晕校正”等主题。有什么指标可以做到这一点吗?就像从0到1的分数一样,分数越低,图像越不可能出现渐晕效应。我提出的简单解决方案之一是测量图像的亮度通道。
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
auto img = imread("my_pic.jpg");
cvtcolor(img, img, cv::COLOR_BGR2LAB);
vector<Mat> lab_img;
split(img, lab_img);
auto const sum_val = sum(lab_img[0])[0] / lab_img[0].total();
//use sum_val as threshold
}
Run Code Online (Sandbox Code Playgroud)
另一个解决方案是通过 CNN 训练分类器,我可以使用渐晕滤波器来生成具有/不具有渐晕效果的图像。请给我一些建议,谢谢。
在图片上使用极坐标扭曲和一些简单的统计数据。您将获得径向强度图。您会看到晕影的特征衰减,还会看到图片内容。该一维信号比整个图像更容易分析。
这不能保证始终有效。我并不是说应该这样做。这是一种方法。
使用中位数、平均值等的变化是可以想象的,但是你也必须引入一个掩模,这样你就知道哪些像素来自图像,哪些像素只是超出范围的黑色(被忽略) 。您可以将源图像扩展为 4 通道,其中第四个通道为全 255。扭曲会将其视为任何其他颜色通道,因此您将获得一个可以使用的“有效”蒙版。
我用 Python 来面对你,因为它是关于思想和 API 的,而且我断然拒绝用 C++ 进行原型设计/研究。
(h,w) = im.shape[:2]
im = np.dstack([im, np.full((h,w), 255, dtype=np.uint8)]) # 4th channel will be "valid mask"
rmax = np.hypot(h, w) / 2
(cx, cy) = (w-1) / 2, (h-1) / 2
# dsize
dh = 360 * 2
dw = 1000
# need to explicitly initialize that because the warp does NOT initialize out-of-bounds pixels
warped = np.zeros((dh, dw, 4), dtype=np.uint8)
cv.warpPolar(dst=warped, src=im, dsize=(dw, dh), center=(cx,cy), maxRadius=int(rmax), flags=cv.INTER_LANCZOS4)
values = warped[..., 0:3]
mask = warped[..., 3]
values = cv.cvtColor(values, cv.COLOR_BGR2GRAY)
Run Code Online (Sandbox Code Playgroud)
图片1:
图2:
mvalues = np.ma.masked_array(values, mask=(mask == 0))
# numpy only has min/max/median for masked arrays
# need this for quantile/percentile
# this selects the valid pixels for every column
cols = (col.compressed() for col in mvalues.T)
cols = [col for col in cols if len(col) > 0]
Run Code Online (Sandbox Code Playgroud)
plt.figure(figsize=(16, 6), dpi=150)
plt.xlim(0, dw)
for p in [0, 10, 25, 50, 75, 90, 100]:
plt.plot([np.percentile(col, p) for col in cols if len(col) > 0], 'k', linewidth=0.5, label=f'{p}%')
plt.plot(mvalues.mean(axis=0), 'red', linewidth=2, label='mean')
plt.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)
第一张图的情节:
第二张图的情节: