首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在OpenCV上用色调比较原始版本和平滑版本的图像:这足够了吗?

在OpenCV上用色调比较原始版本和平滑版本的图像:这足够了吗?
EN

Stack Overflow用户
提问于 2014-11-15 23:06:08
回答 1查看 1.1K关注 0票数 0

问题是对图片(照相机)和其他类型的图像()进行排序。在另一个问题中,我试图使用提供的ImageMagick来利用脚本化的解决方案。现在,我正在使用另一个答案探讨同样的问题,使用OpenCV。

正如解决方案中所描述的,其想法是将颜色模式转换为HSV,http://docs.opencv.org/trunk/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html图像,并将其https://stackoverflow.com/a/17186161通道与原始图像进行比较;然后,根据据称类似漫画的图像在这方面与现实生活中的图像不同(因为它们对操作的反应不同),做出一个http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#mean。所以我试着:

代码语言:javascript
复制
#include "imgproc/imgproc.hpp"
#include "highgui/highgui.hpp"
#include "cv.h"  
#include <iostream>   
#include <stdio.h>  

using namespace std;
using namespace cv;

int main(int argc, char *argv[]) {

//takes filename as argument i.e. ./smooth one.jpg  
    cv::Mat input, output, hsv;
    input = imread(argv[1],1);

//Resize to 300
    Size size(300,300);
    resize(input,input,size);

//Change original image color mode to HSV
    cvtColor(input,hsv,CV_RGB2HSV);

//Separate channels; keep hue on h_image
    std::vector<cv::Mat> hsv_channels, hsv_channelsOUT;
    cv::split(hsv, hsv_channels);
    cv::Mat h_image = hsv_channels[0];

//Apply smoothing/blur on h_image, to output        
    bilateralFilter(h_image,output,60,120,30);

//Split output(already just H) to extract H array for mean later
    cv::split(output, hsv_channelsOUT);
    cv::Mat O_imageH = hsv_channelsOUT[0];

//Average all differences between H values pre/post blur
//Compare h_image with h_image+bilinearF visually to see
    Scalar h = mean(hsv_channels[0]-hsv_channelsOUT[0]);

//Print that to console 
    printf("H: %f\n", h[0]);

//Showcase all the steps; comment to use to binary in scripts
//All windows piled up on top of another one at runtime; move to see
cv::imshow("input",input);
cv::imshow("hsv",hsv);
cv::imshow("h_image",h_image);
cv::imshow("output",output);
cv::imshow("h_image+bilinerarF",O_imageH);

//exit on keypress on image displayed
    waitKey();   
    return 0;   
  }

它在这幅图像这幅画上产生类似的结果(两个“真实”图像,用于查看值中是否有相似之处,即它们的类型相同):

我们正在比较序列中的第3和第4图像,这是一个通道与同一个通道图像平滑。H通道中元素差值平均值的结果(0):

代码语言:javascript
复制
JFK        H: 7.313056
Landscape: H: 8.265544

我不知道如何设置bilateralFilter,因为我不知道什么是sigma空间等等,我最初将它设置为在OpenCV文档示例中生成的最大值(参见intro)。我将这些值加倍,因为这扩大了某些类型图像之间的H值的差异(我认为这在一定程度上隔离了它们的范围)。所有的黑线艺术在白色将产生0为他们的H值-只是一个副作用所做的,他们的色调通道是黑色的任何一种方式。因此,这些可以很容易地归类为这样。我没有足够的图像集来做出预测并相应地调整bilateralFilter。我的相机图像在H: 4-5;7-9;我得到的最小值(0.08)是从蓝色到绿色的相同的非不透明三角形(图形);所有这些都是在太小的样本上观察到的,无法推断出任何有意义的东西。

Q.,所以我想知道我是否正确地实施了这个想法(根据我所依据的解决方案 )?我是否应该得出这样的结论:需要一个更有弹性的程序(使用许多特性)来完成我想做的事情?我应该以不同的方式设置bilateralFilter吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-17 21:35:59

这在某种程度上可行。怎么调这个还不清楚。但是,我未能正确地组合元素,用ImageMagick创建索引。我也有一些问题,脚本用来将它粘合在一起,但提供了一些帮助。所以我能让它正常工作(正常):

代码语言:javascript
复制
#!/usr/bin/env sh

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## -=Try to sort images based on content (helper script)=-
## re: http://stackoverflow.com/q/26951796
## We will generate values for each jpg with our OpenCV thing, sort, then index
## accordingly with IM.
## Our challenge is that we cannot supply 307 jpgs at a time for final montage
## So we'll split that in rows of 15 images.
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

##OpenCV## find all files in current dir/subdirs, run our OpenCV binary
# which echoes the name of the file: H: value #################################

find . -type f -name '*.[Jj][[Pp][Gg]' -exec sh -c '
    for file do
    echo -n "$file: "
    ./smooth "$file"   #name of our OpenCV binary in local dir only
done
' sh {} + | sort --version-sort -k3 | tee Hout | cut -d ':' -f 1,1 > Hpaths_sorted

##ImageMagick - "montage" can't make an index with 100s of images at 100x100
# on my rig; so horizontal strips of 15 images; we will have $z many strips
# i.e. ceiling for not fully populated row ############################

a="1"
h="15"
j="$(cat Hpaths_sorted | wc -l)"
z="$(echo "a=$j; b=$h; if ( a%b ) a/b+1 else a/b" | bc)"

for i in $(seq 1 "$z"); do 

    strip=$(awk "NR>=$a&&NR<=$h" Hpaths_sorted)
    if [ "$h" -gt "$j" ]; then
        montage $(echo "$strip"| tr '\n' ' ') -tile x1 -geometry 100x100+0+0 $i.gif
    else
        montage $(echo "$strip"| tr '\n' ' ') -tile 15x -geometry 100x100+0+0 $i.gif
        a="$(echo $(($a+15)))"
        h="$(echo $(($h+15)))"
    fi

    target="$target $i.gif"

done

# Use our $target to supply the list of files(strips), make one index, 1 row x #strips to final.gif

montage $target -tile 1x$z -geometry '1x1+0+0<' final.gif

它在我们的358映像集上产生:

低值位于顶部,我可以看到一些分组(我们已经正确地生成了不完整的行)。因此,它在最简单的形式上可能不那么有用,但它肯定可以用于值得探索的地方。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26951796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档