Revision [23023]

This is an old revision of OctaveBildverarbeitung made by ToBo on 2016-03-12 01:03:53.

 

Basic Image Processing with Octave



GNU Octave Version 3.0.5
Operating System: Linux 2.6.31-21-generic #59-Ubuntu SMP Wed Mar 24 07:28:56 UTC 2010 i686


Load an image
I = imread('kanu2010.jpg');


Check image size
whos I
ans =

   375   500     3



View images
show.m
figure(1);
subplot(1,2,1);
image(I/4);
axis off equal tight;
title('Original');
subplot(1,2,2);
image(J/4);
axis off equal tight;
title('Bearbeitet');


Better alternative to imshow():
show.m
figure(1);
subplot(1,2,1);
imshow(I/4);
title('Original');
subplot(1,2,2);
imshow(J/4);
title('Bearbeitet');




Image histogramm
[h,b,c] = size(I);
v = reshape(I, h*b*c,1,1);
figure(2);
hist(v,256/5)


image




Example 1

Reduce brightness by -50 steps
Increase contrast by +30 %
J=(I-50)*1.3;

image


Example 2


Reduce green channel by 50 %
J=I;J(:,:,2)=J(:,:,2)/2;


image


Example 3


Calculate gray image
J=fix(I); % uint8 in real umwandel
J(:,:,1)=(J(:,:,1)+J(:,:,2)+J(:,:,3))/3;  % Mittelwert aus allen Kanälen
J(:,:,2)=J(:,:,1); % Kanal kopieren
J(:,:,3)=J(:,:,1); % Kanal kopieren

image


Example 4


Copy green channel to red channel. Green and blue channels stay untouched.
J=I;J(:,:,1)=I(:,:,2)


image

Example 5


Exchange green and blue channels. ;-)
J=I;J(:,:,2)=I(:,:,3);J(:,:,3)=I(:,:,2);


image


Example 6


Blur image using a simple low-pass filter.
J=I; for c=1:3; J(:,:,c) = filter2(ones(5,5)/25,fix(I(:,:,c)));end


image


Example 7


Kanten hervorheben, dem Bild einen Eindruck der Schärfe verleihen

Oder bildverarbeitungsmathematisch ausgedrückt: Die Kanten detektieren, diese mit einem Faktor (hier 1.5) multiplizieren und zum Originalbild addieren.

Die Kanten wurden hier mit dem Tiefpass aus Beispiel 6 detektiert, indem das tiefpassgefilterte Bild von dem Original subtrachiert wurde. Das ergibt ein hochpass-gefiltertes Bild, also die Kanten. Wir drücken auch hier ein Auge zu, dass es sich um ein moving avarage filter handelt.

Ganz deutlich ist der Effekt unten, rechts im Bild am Wasser zu sehen. Es wirkt schärfer und glänzender. Wer das nicht sieht, dann den Faktor (hier 1.5) hochdrehen, näher an den Bildschirm treten oder zum Augenarzt gehen. ;-)

J=I;
for c=1:3; J(:,:,c) = filter2(ones(5,5)/25,fix(I(:,:,c)));end
J=(I-J)*1.5;
J=I+J;


image


Example 8


SW-Bild erzeugen

Ein anderes Bild wird geladen
I = imread('andreas.jpg');


Zunächst erzeugen wir ein Graustufenbild
J=fix(I); % uint8 in real umwandeln
J(:,:,1)=(J(:,:,1)+J(:,:,2)+J(:,:,3))/3;  % Mittelwert aus allen Kanälen
J(:,:,2)=J(:,:,1); % Kanal kopieren
J(:,:,3)=J(:,:,1); % Kanal kopieren


und jetzt berechnen wird daraus ein SW-Bild
J=((K+77)>128)*255;  % SW-Bild erzeugen


image

Weißanteil berechnen
[n,m]=size(J);length(find(J>128))/(n*m)*100


Weißanteil: 78 %


Example 9


Spielerei! schwarz, rot, gold

J(:,:,1)=((K(:,:,1)+77)>128)*255;show;
J(:,:,2)=((K(:,:,2)+60)>128)*255;show;
J(:,:,3)=((K(:,:,3)+47)>128)*255;show;


image


Example 10


Special effects ;)
J=-sin(I/25)*128+128;


image


Example 11


Edge detector according to an algorithm by Rachid Deriche.
for k=1:3; J(:,:,k)=deriche(I(:,:,k),2,0)*4;end ;


image





BildRaetsel




Siehe auch
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki