Image Conditional Sum on Boundry
2 views (last 30 days)
Show older comments
Hello, I have the script shown below. Just read in an image into it and it performs some calculations. im2bw has already been used on the images so they are lack and white
function [mom] = central_moments(inimage, 3)
[xpos, ypos, val] = find(im2double(inimage));
[p, q] = size(inimage);
BW = bwperim(inimage);
for r = 1:p
for c = 1:q
moma(1,1) = sum(val(BW(r,c)==1));
momb(1,1) = sum(val(BW(r,c)==0));
mom(1,1)= moma(1,1) + momb(1,1)
% I want this to give the same result as using
% mom(1,1)= sum(val);
end
end
My final objective is to find Hu's moments for an image with a different weighting based on if the pixel is on the boundary/edge or not. If I could give a certain weight to moma or momb I think I could achieve my objective.
0 Comments
Accepted Answer
Image Analyst
on 19 Jan 2014
Have you read the documentation in find for what the third return argument is? Evidently not. You should read it.
And why do you have moma, momb, and mom as arrays but all you ever set is the (1,1) element? So it's really not an array but just a scalar. And you overwrite that every time so the value it has after the loop is the value for r,c, so all the iterations you did before that were completely for nothing. Have you stepped through this with the debugger to see what values are being assigned at each step?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!