I'm a new user of matlab. I want to write a code for zooming an image by a factor of 1.5 by pixel replication method.But my code takes the value of 1.5 as 1. Anyone ans me...

27 views (last 30 days)
clc;
clear all;
close all;
b=imread('cameraman. tif) ;
figure;
imshow(b) ;title('original image') ;
[m, n, d] =size(b) ;
k=1;
l=1;
f=input('Enter the zooming factor') ;
for i=1:m
for t=1:f
for j=1:n
for t=1:f
for x=1:d
c(k,l,x)=b(i,j,x)
end
l=l+1;
end
end
l=1;
k=k+1;
end
end
figure;
imshow(c);
title('zoomed image') ;
  9 Comments

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 30 Apr 2018
for t=1:f
means to start t at 1, and then each time through, add 1 to it, stopping when the value is greater than the end point, f. When f is 1.5, then that would be for t=1:1.5 . t=1 satisfies the conditions of not being greater than 1.5, so t = 1 is used. Then 1 is added to that, getting 2, and 2 is compared to 1.5 and found to be greater.
Effectively when you use an integer start and an integer increment, for t=1:f would be equivalent to for t=1:floor(f)
Also you are using the same variable names in your nested loops -- for i, then for t, then for j, then for t again. That is going to confuse the readers. But you never use t inside your loops, which is also going to confuse the readers.

Florian Morsch
Florian Morsch on 2 May 2018
Do you want to zoom into a specific area or do you just want to make you whole picture bigger or smaler? If so you can use 'imresize()' to resize your orginal image. Just get your image size with 'size()', multiply that by 1.5 and resize the image with the new size.
  2 Comments
Guillaume
Guillaume on 2 May 2018
Just get your image size with 'size()', multiply that by 1.5 and resize the image with the new size
You don't need to get the image size to zoom by a factor of 1.5, you can pass the zooming factor directly to imresize.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!