Wiki source for OctaveBildverarbeitung


Show raw source

=====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

This are very simple image processing examples. I might by good to get basic understanding of how you can manipulate images.

Some basics first!

How to load an image? Download one of my images or use your own. Do not take big images for testing save time waiting for images being processed.
%%(matlab)
I = imread('kanu2010.jpg');
%%
http://tnotes.de/images/kanu2010.jpg

Check image size
%%
whos I
ans =

375 500 3
%%
Width, Length, number of colors.


View images
%%(matlab;;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');
%%
Bearbeitet is German and it means processed. this page was previously in German.

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



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

{{image url="images/OctaveImHist.png"}}

Try to interprate the histogramm looking at the image. How many bright and dark pixels can you see in the image? Is the image oversaturated (intensity 255) somewhere?



Now, lets start with some very basic examples.

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

{{image url="images/OctaveImEx1.jpg"}}


===Example 2===

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

{{image url="images/OctaveImEx2.jpg"}}


===Example 3===

Calculate gray image
%%(matlab)
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 url="images/OctaveImEx3.jpg"}}


===Example 4===

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

{{image url="images/OctaveImEx4.jpg"}}


===Example 5===

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

{{image url="images/OctaveImEx5.jpg"}}


===Example 6===

Blur image using a simple moving average low-pass filter. Moving average is not the best choice but lets keep it simple.
%%(matlab)
J=I;
for c=1:3;
J(:,:,c) = filter2(ones(5,5)/25,fix(I(:,:,c)));
end
%%

{{image url="images/OctaveImEx6.jpg"}}


===Example 7===

Detect edges and add the edges to the original image, giving the image more sharpeness.

You should see the difference clearly on the water. If not just increase the factor 1.5 to 3 ore more

We reuse the low-pass filter from above to get a low-pass filtered iamge. And then we take the original (I) and substract the low-pass filtered image (I-J). This give us a high-pass filtered image (H). The high-pass filtered image represents the edges.

Finally, we add the high-pass filtered image multiplied by a factor (H) to the original image (I).

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

{{image url="images/OctaveImEx7.jpg"}}


===Example 8===

Generate a black and white image. Just two colors: white and black!

Load another image.
%%(matlab)I = imread('andreas.jpg');%%

First generate a gray image.
%%(matlab)
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
%%

Now, calculate a threshold and generate the black and white image.
%%(matlab)
J=((K+77)>128)*255; % SW-Bild erzeugen
%%

{{image url="images/OctaveImEx8.jpg"}}

Calculate the percentage of white pixels.
%%(matlab)
[n,m]=size(J);length(find(J>128))/(n*m)*100
%%

White pixels: 78 %


===Example 9===

Generate a three color image using only black, red and yellow colors.

%%(matlab)
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 url="images/OctaveImEx9.jpg"}}


===Example 10===

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

{{image url="images/OctaveImEx10.jpg"}}


===Example 11===

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

{{image url="images/OctaveImEx11.jpg"}}




Now, it's your turn trying your own manipulations. I am sure you did already. ;-)




----
Siehe auch {{backlinks}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki