这里, im是输入图像(rgb图像)。 这个成本函数将返回什么?
function G=costfunction(im) G=zeros(size(im,1),size(im,2)); for ii=1:size(im,3) G=G+(filter2([.5 1 .5; 1 -6 1; .5 1 .5],im(:,:,ii))).^2; end endHere, im is an input image (rgb image). What will this cost function return?
最满意答案
这一点:
filter2([.5 1 .5; 1 -6 1; .5 1 .5],im(:,:,ii))将拉普拉斯滤波器应用于im一个2D切片。 通常,拉普拉斯滤波器实现为[0 1 0; 1 -4 1; 0 1 0] [0 1 0; 1 -4 1; 0 1 0] [0 1 0; 1 -4 1; 0 1 0]或[1 1 1; 1 -8 1; 1 1 1] [1 1 1; 1 -8 1; 1 1 1] [1 1 1; 1 -8 1; 1 1 1] 。 我想无论是谁编写这段代码都无法在这两者之间作出决定并取平均值。
循环遍历3D图像im中的每个2D切片,并将每个结果的平方加在一起。 如果im是RGB图像,它将过滤器应用于每个颜色通道,并添加结果的平方。
拉普拉斯算子对图像中的细线以及图像边缘周围的响应(正和负)给出强烈的负面响应。 通过取平方,所有回答都是积极的。 请注意,成本函数在边缘上将接近于零,但在边缘的内部和外部都很高。
This bit:
filter2([.5 1 .5; 1 -6 1; .5 1 .5],im(:,:,ii))applies a Laplace filter to one 2D slice of im. Usually, the Laplace filter is implemented as [0 1 0; 1 -4 1; 0 1 0] or [1 1 1; 1 -8 1; 1 1 1]. I guess whoever wrote this code couldn't decide between those two and took the average.
The loop runs through each of the 2D slices in the 3D image im, and adds the square of each of the results together. If im is an RGB image, it will apply the filter to each of the color channels, and add the square of the results.
The Laplace operator gives a strong negative response on thin lines in the image, as well as responses (positive and negative) around the edges in an image. By taking the square, all responses are positive. Note that the cost function will be close to zero on edges, but high just inside and outside the edges.
更多推荐
发布评论