Image processing calculations edge
显示 更早的评论
I have a script that performs calculations on a image. I want to have the pixels on the edge to have different weighing in this calculation.
I believe the eta20 being produced normally (without the *2) is correct. I'd like to be able to manipulate its value by changing the weight assigned to the boundary pixels
a = ['1.jpg'];
b = imread(a);
a = double(a);
[M, N] = size(a);
[x, y] = meshgrid(1:N, 1:M);
[p, q] = size(b); % Turning image into matrix or p by q dimensions
% Turn x, y, and a into column vectors.
x = x(:);
y = y(:);
a = a(:);
BW = edge(b,'sobel'); %inbuilt matlab function that gives '1' for boundary pixels
imshow(BW)
% Loop through the matrix which is assigning different moments if the pixel
% is on the boundary or not.
for r = 1:p
for c = 1:q
if BW(r,c)==1 %If value is 1 pixel is on the boundary
m.m00 = sum(a);
m.m10 = sum(x .* a);
m.m01 = sum(y .* a);
m.m20 = sum(x.^2 .* a)*2; % *2 has no on effect on eta20
else
m.m00 = sum(a);
m.m10 = sum(x .* a);
m.m01 = sum(y .* a);
m.m20 = sum(x.^2 .* a)*2; %*2 has effect on eta20
end
end
end
xbar = m.m10 / m.m00;
ybar = m.m01 / m.m00;
e.eta20 = (m.m20 - xbar*m.m10) / m.m00^2
If someone could explain what I did wrong? I know its probably more math than matlab.
Note: The final purpose is to calculate Hu's moments which consider the pixels at the edge of the image to be more important in the final calculations but that's exactly what isn't happening
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Color Segmentation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!