Javascript Canvas边缘检测

时间:2014-03-11 15:44:46

标签: javascript image-processing canvas

我想在Canvas中实现这种图像处理效果:

WebGL image processing

我需要的是边缘检测算法或解释,只能绘制用户可以提交的图像的黑色像素或边框元素(例如面部)。

欢呼声

2 个答案:

答案 0 :(得分:3)

按照您的想法,第一步是边缘检测。下面的示例显示了使用MarvinJ检测边缘的热点。有了边缘,你可能会得到物体轮廓。

输入图片

enter image description here

边缘检测:



survTime=np.array([400, 800, 1100, 900])
age=np.array([40, 40, 40, 40])
counter_1yr=0
counter_2yr=0
counter_3yr=0
n=1
for i in survTime:
     for j in age:
        if survTime[i] > 365 and age[j] < 50:
            counter_1yr+=1
            n+=1
            continue
        elif survTime[i] > 730 and age[j] < 50:
            counter_2yr+=1
            n+=1
            continue
        elif survTime[i] > 1095 and age[j] < 50:
            counter_3yr+=1
            n+=1
            continue
print("1 year probability: ", counter_1yr/n)
print("2 year probability: ", counter_2yr/n)
print("3 year probability: ", counter_3yr/n)
&#13;
var canvas = document.getElementById("canvas");

image = new MarvinImage();
image.load("https://i.imgur.com/ZHgkM9w.jpg", imageLoaded);

function imageLoaded(){
  var imageOut = new MarvinImage(image.getWidth(), image.getHeight());
  
  // Edge Detection (Prewitt approach)
  Marvin.prewitt(image, imageOut);
  // Invert color
  Marvin.invertColors(imageOut, imageOut);
  // Threshold
  Marvin.thresholding(imageOut, imageOut, 220);
  imageOut.draw(canvas); 
}
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我按照MarkE的建议使用了JsFeat,干杯!

http://inspirit.github.io/jsfeat/