1
$\begingroup$

Assume a 2-D signal (i.e., some image). Load image and assume it to be signal x. Next assume that instead of having a 2-D filter you have two one D filters

$$f_1[n] =\begin{bmatrix}0.25 && 0.5 && 0.25\end{bmatrix}$$ and $$f_2[n]=\begin{bmatrix}0.25 \\ 0.5 \\ 0.25\end{bmatrix}$$ Assume that the convolution

$$f_1[n]* f_2[n] = f_3[n]= \begin{bmatrix}0.0625 && 0.125 && 0.0625\\ 0.125 && 0.25 && 0.125\\0.0625 && 0.125 && 0.0625\end{bmatrix}$$


Using this information and output at each stage verify that Associative property holds.

My code:

f3 = [0.0625 0.125 0.0625; 0.125 0.25 0.125; 0.0625 0.125 0.0625]
x=imread('img.jpg')
conv2('x, f3)

But this gives error saying x is not a vector. How do I fix this?

$\endgroup$
4
  • $\begingroup$ It would be nice if you could edit your post with a more readable typesetting of the matrices, etc. $\endgroup$ Apr 1, 2017 at 18:45
  • 1
    $\begingroup$ Did what Laurent asked for, Maya, because I agree with him! You just have to use single or double $ around your TeX formulas instead of **! $\endgroup$ Apr 2, 2017 at 8:06
  • $\begingroup$ @MarcusMüller I didn't know that! $\endgroup$
    – Maya
    Apr 2, 2017 at 10:34
  • $\begingroup$ @Maya that's why I'm telling you ;) Have a great day! $\endgroup$ Apr 2, 2017 at 10:41

1 Answer 1

0
$\begingroup$

You should show that conv2(f3,x) can be implemented in a separable way. In other words, computing x1 = conv2(f1,x), then applying f2 on the results, x12 = conv2(f2,x1) gives the same result. Or f12 = conv2(f2,f1) then x12 = conv2(f12,x).

You should be aware of the correct "dimensions" for f1 and f2: transpose of each other, so that one works on "rows" and the other on columns.

This is shown in the following Matlab code:

dataImage = zeros(25,25);
% Create a delta-like image
dataImage(13,13)=1;
% Create a random-kernel image
dataImage(11:13,11:13)=rand(3,3);
imagesc(dataImage);colormap gray

f1 = [0.25 0.5 0.25]'; f2 = [0.25 0.5 0.25];
disp(f1*f2);

f3 = [0.0625 0.125 0.0625; 0.125 0.25 0.125; 0.0625 0.125 0.0625];
disp(f3);

dataImagef1f2 = conv2(f2,conv2(f1,dataImage));

dataImagef1f2 = conv2(conv2(f2,f1),dataImage);

dataImagef3 = conv2(f3,dataImage);

subplot(2,2,1)
imagesc(dataImage);
xlabel('data')

subplot(2,2,2)
imagesc(dataImagef1f2);
xlabel('(data*f1)*f2')

subplot(2,2,3)
imagesc(dataImagef1f2);
xlabel('(f1*f2)*data')

subplot(2,2,4)
imagesc(dataImagef3);
xlabel('f3')

Suggestions for tutorials:

$\endgroup$
6
  • $\begingroup$ Can you tell me whay did you create kernel and delta like images? And why does it have to be grayscale image? I am new to image processing/ $\endgroup$
    – Maya
    Apr 1, 2017 at 18:35
  • $\begingroup$ For the demo mostly, and to avoid side effects on the borders of the images. Having enough zeros around avoid some practical issues. Plus, the linearity of convolution entails that if you prove the associativity for the dirac image, then the result extends to other images. And it would work for color images, for instance by working on different color places. This is more a Matlab-type question $\endgroup$ Apr 1, 2017 at 18:42
  • $\begingroup$ Can you suggest me a good resource to study image processing in matlab? $\endgroup$
    – Maya
    Apr 1, 2017 at 22:07
  • $\begingroup$ I am studying this course 'signals and systems" in university and have just begun using matlab but I cannot find detailed tutorial about image processing in thus course book : Attaway's Introduction to Matlab $\endgroup$
    – Maya
    Apr 5, 2017 at 18:40
  • $\begingroup$ I don't have enough rep to upvote, sorry :/ $\endgroup$
    – Maya
    Apr 5, 2017 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.