# how can i imagie zoom with Convolution method

7 views (last 30 days)
Edited: Image Analyst on 25 Jan 2023
for example i have a matrix of [3 5 7;2 7 6; 3 4 9]
and i want to zoom it with the method of Convolution which i add zeros all around it to become like this:
Next, we use convolution mask, which is slide a cross the extended image, and perform simple arithmetic operation at each pixel location :
For example, if we put the mask over the upper-left corner of the image, we obtain (from right to left, and top to bottom):
1/4(0) +1/2(0) +1/4(0) +1/2(0) +1(3) +1/2(0) + 1/4(0) +1/2(0) +1/4(0) =3
The next step is to slide the mask over by one pixel and repeat the process, as follows:
1/4(0) +1/2(0) +1/4(0) +1/2(3) +1(0) +1/2(5) + 1/4(0) +1/2(0) +1/4(0) =4
until the end, then move down one pixel and repeat the process until the end so i have a new matrix
i had a hard time trying to figure the code, so i would really appreciate the help
Walter Roberson on 25 Jan 2023
If you are trying to tell us that you are doing a homework assignment in which you are not permitted to use conv2() and need to write that functionality yourself, then we would suggest that it is easy enough to write as two for loops.

Image Analyst on 25 Jan 2023
Edited: Image Analyst on 25 Jan 2023
Convolution is fast and efficient. It's inserting the zeros that's going to be a pain, and slow.
The final result is an interpolation.
To do that interpolation more efficiently (without inserting zeros) you can use imresize or interp2
If you need a manual convolution program, see my attached demo.

Walter Roberson on 25 Jan 2023
It is deliberate that the following does not do exactly what you want to do. It is also deliberate that it has some extra steps that are not needed for your purposes. This code illustrates that the task can be done; figuring out what parts of it are surplus is part of your learning experience.
imshow(img);
max(img, [], 'all')
ans = uint8 255
img2 = zeros(size(img,1)*2+1, size(img,2)*2+1, size(img,3), 'like', img);
img2(2:2:end, 2:2:end, :) = img;
imshow(img2);
mask = [1/9 1/3 1/9; 1/3 2/3 1/3; 1/9 1/3 1/9]
0.1111 0.3333 0.1111 0.3333 0.6667 0.3333 0.1111 0.3333 0.1111
max(img3a,[],'all')
ans = 170
img3 = uint8(rescale(img3a, 0, 255));
imshow(img3)

### Categories

Find more on Images in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by