How can I move a 7x7 filter around an image?

1 view (last 30 days)
Agustin
Agustin on 15 Apr 2017
Commented: Agustin on 17 Apr 2017
So I have an estimated filter, theta, to apply it to a blurred image. For each pixel on the image I have to do the following:
ys = zs * theta
Where zs is a 7x7 window sorrounding pixel s and theta is the minimum square error to adjust the blurred image. How can I move the 7x7 window filter around the image, especially when I select pixels that are located at the edge of the image?
  1 Comment
Agustin
Agustin on 16 Apr 2017
Edited: Agustin on 16 Apr 2017
Well, zs is the one that I need to work on. zs is a row vector of a set of pixels that belong to a window surrounding pixel s in the blurred image X. I need to evaluate the 7 x 7 window on each pixel but I'm not sure what I need to do when I select a pixel that is for example, on the top left corner of the image. Once I have zs I know what to do. ys = zs * theta is for one pixel. ys is the pixel of an image Y.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 15 Apr 2017
For a simple multiplication, you can use conv2(). Assuming zs is the 2-D input image:
ys = conv2(zs, imrotate(theta, 180), 'same');
If zs is uint8 or uint16, cast to double before you pass it to conv2():
ys = conv2(double(zs), imrotate(theta, 180), 'same');
or use imfilter():
ys = imfilter(zs, theta);
  3 Comments
Image Analyst
Image Analyst on 16 Apr 2017
If zs is a row vector - one complete row from an image - then ys is also a row vector since you're just multipling it by a scalar theta. So where does the 7x7 window come into play? And anyway, how do you apply a 7x7 2-D square window to a 1-D vector?
Agustin
Agustin on 17 Apr 2017
zs is a 7x7 window of pixels surrounding pixel s. After I have my window, I reshape it so it becomes a 1 x 49 row vector. Theta is a 49 x 1 vector. so zs * theta should give one value for each pixel in Y.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!