Image processing calculations edge

2 views (last 30 days)
Minhal
Minhal on 22 Dec 2013
Commented: Minhal on 23 Dec 2013
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

Accepted Answer

Image Analyst
Image Analyst on 22 Dec 2013
BW equals 1 not just for the boundary but everywhere it's true. If you want to find pixels on the boundary, use bwperim:
boundaryPixels = bwperim(BW);
[boundaryRows, boundaryCols] = find(boundaryPixels);
  3 Comments
Image Analyst
Image Analyst on 23 Dec 2013
It will not be the opposite. Edges will still be indicated by white lines.
There is nothing to change. If you do
if BW(r,c)==1
then it will do what follows ("the first calculation") if the pixel is on the boundary, just like you asked.
Minhal
Minhal on 23 Dec 2013
Thanks a lot. So the the calculation now considers the boundary pixels. Perfect I really appreciate your help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!