LAT Hologramm-Software 2.0
Loading...
Searching...
No Matches
ResizeImage.m
Go to the documentation of this file.
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Funktion
3%
4% Optionen für Mode: 'stretch', 'original', 'repeat'
5%
6% Projekt: "Hologrammsoftware 2.0"
7%
8% Autor: Jan Marx
9% Zuletzt bearbeitet: 28.09.2022
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11function [image] = ResizeImage(input, x,y,mode)
12%Passt ein Bild an eine andere Auflösung an.
13% Verschiedene Anpassungsoptionen wählbar, s.u.
14y0 = size(input,2);
15x0 = size(input,1);
16
17if(x0==x && y0==y)
18 image = input;
20elseif (mode == "stretch")
21 %Strecken des Bildes
22 image = imresize(input, [x y], 'nearest');
23
24elseif (mode == "original")
25 %Beibehalten der Originalauflösung.
26 %Ist das Bild größer als die Zielauflösung, wird es mittig
27 %ausgeschnitten
28 %Ist das Bild kleiner als die Zielauflösung, werden Nullen um das Bild
29 %ergänzt (vgl. Zero-Padding)
30 if(x0<=x && y0<=y)
31 image = zeros(x,y);
32 image(floor((x-x0)/2)+1:floor((x+x0)/2),floor((y-y0)/2)+1:floor((y+y0)/2))=input;
33 elseif(x0>=x && y0>=y)
34 image = input(floor((x0-x)/2)+1:floor((x0+x)/2),floor((y0-y)/2)+1:floor((y0+y)/2));
35 elseif(x0<=x && y0>=y)
36 image = zeros(x,y);
37 image(floor((x-x0)/2)+1:floor((x+x0)/2),:)= input(:,floor((y0-y)/2)+1:floor((y0+y)/2));
38 elseif(x0>=x && y0<=y)
39 image = zeros(x,y);
40 image(:,floor((y-y0)/2)+1:floor((y+y0)/2))=input(floor((x0-x)/2)+1:floor((x0+x)/2),:);
41 end
42
43elseif (mode == "repeat")
44 %Ist das Bild kleiner als die Zielauflösung, so wird ein sich
45 %wiederholendes Muster des Bildes erzeugt
46 image = zeros(x,y);
47 for ki=1:x
48 for kj=1:y
49 image(ki,kj) = input(mod(ki,x0)+1,mod(kj,y0)+1);
50 end
51 end
52
53
54else
55 image = 0;
56 disp('ERROR - Unknown Image ResizeMode');
57end
58
59
60end
61
62
function ResizeImage(in input, in x, in y, in mode)
Passt ein Bild an eine andere Auflösung an. Verschiedene Anpassungsoptionen wählbar.