how can i imagie zoom with Convolution method
7 views (last 30 days)
Show older comments
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
4 Comments
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.
Answers (2)
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.
img = imresize(imread('flamingos.jpg'), [32 24]);
imshow(img);
max(img, [], 'all')
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]
img3a(:,:,3) = conv2(double(img2(:,:,3)), mask);
img3a(:,:,2) = conv2(double(img2(:,:,2)), mask);
img3a(:,:,1) = conv2(double(img2(:,:,1)), mask);
max(img3a,[],'all')
img3 = uint8(rescale(img3a, 0, 255));
imshow(img3)
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!