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...
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 18 Feb. 2021
It is obviously a homework question. http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Antworten (2)
Walter Roberson
am 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.
0 Kommentare
Florian Morsch
am 2 Mai 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 Kommentare
Walter Roberson
am 2 Mai 2018
I suspect that this is an assignment to use pixel replication deliberately.
Guillaume
am 2 Mai 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.
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!