Overview
This is a simple tutorial to get you started with Matlab. Matlab makes it easy to perform scientific computations without having to learn a programming language such as Fortran, C, or C++. This tutorial is developed keeping assignment_0.pdf for AM205 in mind. It can be used for other classes or self-learning as well.
...
This depends on your operating system. On Mac, it is usually installed in /Applications and you should see a Matlab icon with a MATLAB_<version number>. Double clicking the icon should open it. On Windows, there should either be a shortcut on the desktop or it can be found under programs in the start-up.
Matlab interfaceMatlab Development Environment (Matlab Desktop):
This changes can change with new releases. The following youtube video gives a quick introduction:
...
Code Block |
---|
%%The primary functions for loading images is 'imread' and for displaying images is 'imshow'. im=imread('baboon.png'); imshow(im); %% Images are basically two dimensional array of pixels (picture elements) with a third dimension %% that shows the intensity of pixel. If the image is a gray scale image,, the intensity is a single number %% at each pixel. If it is a color image, it is stored as a "third dimension" with 3 value %% each corresponding to the intensity of r (red), g (green) and b (blue) colors. Thus if we do: size(im) %% The result is 512 512 3, which indicates it is a two dimensional array of 512 x 512 pixels with three colors. %% To get the 'red' intensity, you can do: r=im(:, :, 1); %% This is now a two dimensional array. The color intensity can vary anywhere from 8 bits (256 levels) %% for grayscale to 24 bits (8 bits for each color) for color images. There are even 30-, 36-, or 48- bit %% images. As far as Matlab is concerned,. the image once loaded is a three dimensional array with the last %% dimension taking on only 3 values. max(r(:)),min(r(:)) %% will show 255 and 0 (the red color is stored in 8 bits). imshow(r) %% will show the image in grayscale with intensity corresponding to "red" color intensity in the %% original image. You can convert the color image to a grayscale image: img=rgb2gray(im); imshow(img) This is now a two dimensional image with a grayscale intensity of 8 bits. We have compressed the image at the expense of color! |
Grayscale Images:
Code Block |
---|
%% Many medical images (such as MRI, CT, ultrasound, etc.) are likely to be grayscale images. %% They can 10 or 12 bit images and it is convenient to represent them using 16 bits as computers can 16 bits efficiently. A=imread('Brain-MRI.jpg'); size(A) imshow(A) %% We can convert this to an grayscale image with: B=rgb2gray(A) %% This will be a 2D array of pixels with gray shades represented by 8 bits (256 shades). %% We can plot a histogram of color intensity (x-axis intensity, y axis -- number of pixels) with: imhist(B) %% We can reduce the variation in the intensity among the pixels (and thereby visually enhance the darker regions) %% by using the matlab function histeq. histeq(B) %%will display the image with formerly darker regions more bright and brighter regions darker. |