This is my homework question:
Write HW3_func.m
as follows:
function [cogR, cogC] = HW3_func ( f, i )
f
: input grayscale imagei
: intensity level to check- Function should find all the pixels in
f
with intensity ofi
. Then, return the center of gravity of those pixels as[cogR, cogC]
. Center of gravity is computed as the average of the row and average of column. If nopixel == i
, then return[0,0]
I don't understand how to calculate center of gravity. What I have done is:
- Declare a matrix
X
with the same dimension as the image. Initialize it with all zeros - Find the position of the pixels with the given intensity in the input image and replace those positions in
X
with1
.
Am I on the right path?
This is what I have right now:
function [ cogR,cogC ] = HW3_func(f,i)
[r,c] = size(f)
X = zeros(r,c)
for k = 1:r
for j = 1:c
if f(k,j)==i
X(k,j)=1;
end
end
end
%disp(X)
cogR=centroid(X);
cogC=centroid(X,2);
disp(cogR)
disp(cogC)
end