You are on page 1of 9

Rotate an image:

Syntax
B = imrotate(A,angle)
B = imrotate(A,angle,method)
B = imrotate(A,angle,method,bbox)
gpuarrayB = imrotate(gpuarrayA,method)

Description
B = imrotate(A,angle) rotates image A by angle degrees in a counterclockwise direction
around its center point. To rotate the image clockwise, specify a negative value for angle.
imrotate makes the output image B large enough to contain the entire rotated image. imrotate
uses nearest neighbor interpolation, setting the values of pixels in B that are outside the rotated
image to 0 (zero).

B = imrotate(A,angle,method) rotates image A, using the interpolation method specified by


method.

B = imrotate(A,angle,method,bbox) rotates image A, where bbox specifies the size of the


output image. If you specify cropped', imrotate makes the output image the same size as the
input image. If you specify loose', imrotate makes the output image large enough to include
the entirety of the rotated image.

gpuarrayB = imrotate(gpuarrayA,method) perform operation on a graphics processing unit


(GPU), where gpuarrayA is a gpuArray object that contains a grayscale or binary image, and the
output image is a gpuArray object. This syntax requires the Parallel Computing Toolbox.

Matlab Code for Rotating Image by 90 degree


Coding:
close all;
clear all;
a=imread(Your image.png);
c=size(a)
for i = 1:1:c(1)
for j = 1:1:c(2)
b(j,i)=a(i,j);
end
end
figure(),imshow(a),figure(),imshow(b)
size(b)
Crop an Image:
To extract a rectangular portion of an image, use the imcrop function. Using imcrop, you can specify
the crop region interactively using the mouse or programmatically by specifying the size and position of
the crop region.

Syntax
I2 = imcrop
I2 = imcrop(I)
X2 = imcrop(X,map)
___ = imcrop(obj)
I2 = imcrop(I,rect)
X2 = imcrop(X,map,rect)
___ = imcrop(XData,YData,___)
[___,rect2] = imcrop(___)
[XData2,YData2,___] = imcrop(___)

Description
I2 = imcrop creates an interactive image cropping tool associated with the image displayed in
the current figure, called the target image. The Crop Image tool is a moveable, resizable
rectangle that you can position over the image and perform the crop operation interactively using
the mouse. For more information about using the Crop Image tool, see Interactive Behavior.
imcrop returns the cropped image, I2. With this syntax and the other interactive syntaxes, the
Crop Image tool blocks the MATLAB command line until you complete the operation.

I2 = imcrop(I) displays the image I in a figure window and creates a cropping tool associated
with that image. I can be a grayscale image, a truecolor image, or a logical array. imcrop returns
the cropped image, I2.

X2 = imcrop(X,map) displays the indexed image X in a figure using the colormap map, and
creates a cropping tool associated with that image. After you crop the image, imcrop returns the
cropped indexed image, X2.

___ = imcrop(obj) creates a cropping tool associated with the object obj. obj can be an
image, axes, uipanel, or figure. If obj is an axes, uipanel, or figure, the cropping tool acts on the
first image found in the container object.

I2 = imcrop(I,rect) crops the image I. rect is a four-element position vector of the form
[xmin ymin width height] that specifies the size and position of the crop rectangle. imcrop
returns the cropped image, I2.
X2 = imcrop(X,map,rect) crops the indexed image X. map specifies the colormap used with X.
rect is a four-element position vector [xmin ymin width height] that specifies the size and
position of the cropping rectangle. imcrop returns the cropped indexed image, X2.

___ = imcrop(XData,YData,___) specifies a nondefault spatial coordinate system for the


target image.

[___,rect2] = imcrop(___) returns the cropping rectangle in rect2, a four-element position


vector, in addition to the cropped image.

[XData2,YData2,___] = imcrop(___) returns two-element vectors that specify the XData and
YData of the target image.

Codng:
I = imread('circuit.tif')
J = imcrop(I);

close all;
clear all;
a=imread(your image.png);

% Parameter for cropping

x=input(Enter value of Row:)

y=input(Enter value of Column:)


c=size(a)
for i = x:1:c(1)-x
for j = y:1:c(2)-y
b(i+1-x,j+1-y)=a(i,j);
end
end
figure()
imshow(a)
figure()
imshow(b)
size(b)
Displaying Images Using the imshow Function
To display image data, use the imshow function. The following example reads an image into the
MATLAB workspace and then displays the image in a MATLAB figure window.

moon = imread('moon.tif');
imshow(moon);

Syntax
imshow(I)
imshow(X,map)
imshow(filename)
imshow(I,[low high])
imshow(___,Name,Value)
himage = imshow(___)
imshow(I,RI)
imshow(X,RX,map)
imshow(gpuarrayIM,___)

Description
imshow(I) displays image I in a figure, where I is a grayscale, RGB (truecolor), or binary
image. For binary images, imshow displays pixels with the value 0 (zero) as black and 1 as white.
imshow optimizes figure, axes, and image object properties for image display.

imshow(X,map) displays the indexed image X with the colormap map. A colormap matrix can
have any number of rows, but it must have exactly 3 columns. Each row is interpreted as a color,
with the first element specifying the intensity of red light, the second green, and the third blue.
Color intensity can be specified on the interval 0.0 to 1.0.

imshow(filename) displays the image stored in the graphics file specified by filename.

imshow(I,[low high]) displays grayscale image I, specifying the display range as a two-
element vector, [low high]. For more information, see the DisplayRange parameter.

imshow(___,Name,Value) displays an image, using name-value pairs to control aspects of the


operation.

himage = imshow(___) returns the image object created by imshow.

imshow(I,RI) displays the image I with associated 2-D spatial referencing object RI.

imshow(X,RX,map) displays the indexed image X with associated 2-D spatial referencing object
RX and colormap map.
imshow(gpuarrayIM,___) displays the image contained in a gpuArray. This syntax requires the
Parallel Computing Toolbox.

Resize:

Syntax
B = imresize(A,scale)
B = imresize(A,[numrows numcols])
[Y,newmap] = imresize(X,map,___)
___ = imresize(___,method)
___ = imresize(___,Name,Value)
gpuarrayB = imresize(gpuarrayA,scale)
gpuarrayB = imresize(gpuarrayA,[numrows numcols])

Description
B = imresize(A,scale) returns image B that is scale times the size of A. The input image A
can be a grayscale, RGB, or binary image. If A has more than two dimensions, imresize only
resizes the first two dimensions. If scale is from 0 through 1.0, B is smaller than A. If scale is
greater than 1.0, B is larger than A. By default, imresize uses bicubic interpolation.

B = imresize(A,[numrows numcols]) returns image B that has the number of rows and
columns specified by the two-element vector [numrows numcols].

[Y,newmap] = imresize(X,map,___) resizes the indexed image X where map is the colormap
associated with the image. By default, imresize returns a new, optimized colormap (newmap)
with the resized image. To return a colormap that is the same as the original colormap, use the
'Colormap' parameter.

___ = imresize(___,method) specifies the interpolation method used.

___ = imresize(___,Name,Value) returns the resized image where Name,Value pairs control
various aspects of the resizing operation.

gpuarrayB = imresize(gpuarrayA,scale) performs the resize operation on a GPU. The input


image and the output image are gpuArrays. When used with gpuArrays, imresize only supports
cubic interpolation and always performs antialiasing. For cubic interpolation, the output image
might have some values slightly outside the range of pixel values in the input image. This syntax
requires the Parallel Computing Toolbox.

gpuarrayB = imresize(gpuarrayA,[numrows numcols]) performs the resize operation on a


GPU, where [numrows numcols] specifies the size of the output image.
Coding:
a=imread('c:\black and white.jpg');
[rows,columns,layers]=size(a);
i=1;j=1;k=1;
c=zeros(rows/2,columns/2,layers);
c=uint8(c);
for x=1:2:rows-1;
for y=1:2:columns-1;
for z=1:layers;
c(i,j,k)=1/4*(a(x,y,z)+a(x,y+1,z)+a(x+1,y,z)+a(x+1,y+1,z));
k=k+1;
end
j=j+1;
k=1;
end
i=i+1;
j=1;
k=1;
end
figure, imshow(a)
figure, imshow(c)

Simulink:

Simulink, developed by MathWorks, is a graphical programming environment for modeling, simulating


and analyzing multidomain dynamic systems. Its primary interface is a graphical block diagramming tool
and a customizable set of block libraries. It offers tight integration with the rest of the MATLAB
environment and can either drive MATLAB or be scripted from it. Simulink is widely used in automatic
control and digital signal processing for multidomain simulation and Model-Based Design.

How to use an simulink:


1. Start MATLAB. From the MATLAB Toolstrip, click the Simulink button . ...
2. Click the Blank Model template, and then click the Create Model button. The Simulink
Editor opens with a new block diagram.
3. Select File > Save as.

Create an simple model simulink:

To create this simple model, you need four Simulink blocks. Blocks are the model elements that
define the mathematics of a system and provide input signals:

Sine Wave Generate an input signal for the model.


Integrator Process the input signal.
Bus Creator Combine multiple signals into one signal.

Scope Visualize and compare the input signal with the output signal.

Is Matlab is a programming language?

A proprietary programming language developed by MathWorks, MATLAB allows matrix


manipulations, plotting of functions and data, implementation of algorithms, creation of user
interfaces, and interfacing with programs written in other languages, including C, C++, C#,
Java, Fortran and Python.

Gray scale:

Grayscale is a range of shades of gray without apparent color. The darkest possible shade is
black, which is the total absence of transmitted or reflected light. The lightest possible shade is
white, the total transmission or reflection of light at all visible wavelength s. Intermediate shades
of gray are represented by equal brightness levels of the three primary colors (red, green and
blue) for transmitted light, or equal amounts of the three primary pigments (cyan, magenta and
yellow) for reflected light.

RGB File Format


RGB is a file extension for an image file created on a Silicon Graphics workstation. RGB files can contain
Run Length Encoding (RLE) compressed or uncompressed images in grayscale or color, and also supports
optional transparency. RGB files can be opened and edited by most image editors, such as Adobe
Photoshop and the GIMP.

Histogram:
histogram( X ) creates a histogram plot of X . ... histogram displays the bins as rectangles such that the
height of each rectangle indicates the number of elements in the bin. histogram( X , nbins ) uses a
number of bins specified by the scalar, nbins .

Syntax
histogram(X)
histogram(X,nbins)
histogram(X,edges)
histogram('BinEdges',edges,'BinCounts',counts)
histogram(C)
histogram(C,Categories)
histogram('Categories',Categories,'BinCounts',counts)
histogram(___,Name,Value)
histogram(ax,___)
h = histogram(___)

Description
histogram(X) creates a histogram plot of X. The histogram function uses an automatic binning
algorithm that returns bins with a uniform width, chosen to cover the range of elements in X and
reveal the underlying shape of the distribution. histogram displays the bins as rectangles such
that the height of each rectangle indicates the number of elements in the bin.

histogram(X,nbins) uses a number of bins specified by the scalar, nbins.

histogram(X,edges) sorts X into bins with the bin edges specified by the vector, edges. Each
bin includes the left edge, but does not include the right edge, except for the last bin which
includes both edges.

histogram('BinEdges',edges,'BinCounts',counts) manually specifies bin edges and


associated bin counts. histogram plots the specified bin counts and does not do any data
binning.

histogram(C), where C is a categorical array, plots a histogram with a bar for each category in
C.

histogram(C,Categories) plots only the subset of categories specified by Categories.

histogram('Categories',Categories,'BinCounts',counts) manually specifies categories


and associated bin counts. histogram plots the specified bin counts and does not do any data
binning.

histogram(___,Name,Value) specifies additional options with one or more Name,Value pair


arguments using any of the previous syntaxes. For example, you can specify 'BinWidth' and a
scalar to adjust the width of the bins, or 'Normalization' with a valid option ('count',
'probability', 'countdensity', 'pdf', 'cumcount', or 'cdf') to use a different type of
normalization. For a list of properties, see Histogram Properties.

histogram(ax,___) plots into the axes specified by ax instead of into the current axes (gca).
The option ax can precede any of the input argument combinations in the previous syntaxes.

h = histogram(___) returns a Histogram object. Use this to inspect and adjust the properties
of the histogram. For a list of properties, see Histogram Properties.
What is a PNG file?
Portable Network Graphic

A PNG file is an image file stored in the Portable Network Graphic (PNG) format. It contains a
bitmap of indexed colors and uses lossless compression, similar to a .GIF file but without
copyright limitations. PNG files are commonly used to store graphics for web images.

What is a JPEG file?


Joint Photographic Experts Group

A JPEG file is an image saved in a compressed graphic format standardized by the Joint
Photographic Experts Group (JPEG). It supports up to 24-bit color and is compressed using lossy
compression, which may noticeably reduce the image quality if high amounts of compression are
used. JPEG files are commonly used for storing digital photos and web graphics.

You might also like