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!