2+2
ans =
4
a=2
a =
2
a
a =
2
a=2;
a
a =
2
b=zeros(5)
b =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
b=zeros(5,1)
b =
0
0
0
0
0
a= [1 2 3 ]
a =
1 2 3
a
a =
1 2 3
a'
ans =
1
2
3
b = 1:5;
b
b =
1 2 3 4 5
1:25
ans =
Columns 1 through 11
1 2 3 4 5 6 7 8 9 10 11
Columns 12 through 22
12 13 14 15 16 17 18 19 20 21 22
Columns 23 through 25
23 24 25
c = 1:3:20
c =
1 4 7 10 13 16 19
d = 1:3.5:20
d =
1.0000 4.5000 8.0000 11.5000 15.0000 18.5000
clc
e = rand(10,1)
e =
0.8147
0.9058
0.1270
0.9134
0.6324
0.0975
0.2785
0.5469
0.9575
0.9649
f = randn(15,1)
f =
-1.3499
3.0349
0.7254
-0.0631
0.7147
-0.2050
-0.1241
1.4897
1.4090
1.4172
0.6715
-1.2075
0.7172
1.6302
0.4889
hist(randn(10000,1),200)
a=randn(10000,1);
min(a)
ans =
-3.9157
max(a)
ans =
4.0904
a= rand(10,10)
a =
Columns 1 through 8
0.4681 0.8492 0.2788 0.0538 0.3942 0.1035 0.8513 0.7036
0.5686 0.6386 0.7141 0.1484 0.6044 0.3992 0.9643 0.6507
0.9153 0.4979 0.0981 0.0805 0.9963 0.5377 0.5367 0.8682
0.4166 0.9216 0.9140 0.7115 0.1278 0.2159 0.8876 0.3478
0.0888 0.3472 0.7847 0.0700 0.1980 0.3857 0.7497 0.3306
0.7675 0.0221 0.1518 0.5241 0.8878 0.9138 0.1397 0.2938
0.3721 0.0483 0.4211 0.7782 0.0602 0.3621 0.0046 0.0133
0.4885 0.7962 0.9548 0.0715 0.0833 0.5417 0.7913 0.2797
0.2929 0.9709 0.1895 0.6613 0.5858 0.1828 0.5140 0.8578
0.6122 0.7417 0.2734 0.4349 0.0379 0.3415 0.2310 0.1511
Columns 9 through 10
0.5525 0.5824
0.0610 0.5865
0.8462 0.4205
0.9628 0.8331
0.3011 0.1552
0.2332 0.1093
0.9351 0.5232
0.8421 0.5528
0.7798 0.1637
0.5076 0.1494
a= rand(8,8)
a =
0.0603 0.8492 0.2024 0.4907 0.9713 0.4480 0.7463 0.9890
0.4325 0.4206 0.7560 0.3657 0.6318 0.9403 0.5868 0.8064
0.4899 0.8110 0.9443 0.6138 0.4059 0.9786 0.3030 0.0430
0.0053 0.9899 0.8605 0.6534 0.4438 0.4922 0.5851 0.5424
0.2614 0.4332 0.4067 0.2140 0.0068 0.4417 0.5749 0.2647
0.3426 0.9622 0.9514 0.5587 0.3348 0.7977 0.2065 0.5091
0.0135 0.4352 0.4692 0.9563 0.7695 0.1205 0.0571 0.5821
0.7008 0.2074 0.7073 0.8838 0.6461 0.8274 0.2295 0.0456
imagesc(a)
colormap('gray')
a(1,2)
ans =
0.8492
a(1:3,1:3)
ans =
0.0603 0.8492 0.2024
0.4325 0.4206 0.7560
0.4899 0.8110 0.9443
figure(2)
imagesc(a(1:3,1:3))
colormap(gray)
gray
ans =
0 0 0
0.0159 0.0159 0.0159
0.0317 0.0317 0.0317
0.0476 0.0476 0.0476
0.0635 0.0635 0.0635
0.0794 0.0794 0.0794
0.0952 0.0952 0.0952
0.1111 0.1111 0.1111
0.1270 0.1270 0.1270
0.1429 0.1429 0.1429
0.1587 0.1587 0.1587
0.1746 0.1746 0.1746
0.1905 0.1905 0.1905
0.2063 0.2063 0.2063
0.2222 0.2222 0.2222
0.2381 0.2381 0.2381
0.2540 0.2540 0.2540
0.2698 0.2698 0.2698
0.2857 0.2857 0.2857
0.3016 0.3016 0.3016
0.3175 0.3175 0.3175
0.3333 0.3333 0.3333
0.3492 0.3492 0.3492
0.3651 0.3651 0.3651
0.3810 0.3810 0.3810
0.3968 0.3968 0.3968
0.4127 0.4127 0.4127
0.4286 0.4286 0.4286
0.4444 0.4444 0.4444
0.4603 0.4603 0.4603
0.4762 0.4762 0.4762
0.4921 0.4921 0.4921
0.5079 0.5079 0.5079
0.5238 0.5238 0.5238
0.5397 0.5397 0.5397
0.5556 0.5556 0.5556
0.5714 0.5714 0.5714
0.5873 0.5873 0.5873
0.6032 0.6032 0.6032
0.6190 0.6190 0.6190
0.6349 0.6349 0.6349
0.6508 0.6508 0.6508
0.6667 0.6667 0.6667
0.6825 0.6825 0.6825
0.6984 0.6984 0.6984
0.7143 0.7143 0.7143
0.7302 0.7302 0.7302
0.7460 0.7460 0.7460
0.7619 0.7619 0.7619
0.7778 0.7778 0.7778
0.7937 0.7937 0.7937
0.8095 0.8095 0.8095
0.8254 0.8254 0.8254
0.8413 0.8413 0.8413
0.8571 0.8571 0.8571
0.8730 0.8730 0.8730
0.8889 0.8889 0.8889
0.9048 0.9048 0.9048
0.9206 0.9206 0.9206
0.9365 0.9365 0.9365
0.9524 0.9524 0.9524
0.9683 0.9683 0.9683
0.9841 0.9841 0.9841
1.0000 1.0000 1.0000
figure(1)
colormap('jet')
rampImage=1:64
rampImage =
Columns 1 through 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Columns 15 through 28
15 16 17 18 19 20 21 22 23 24 25 26 27 28
Columns 29 through 42
29 30 31 32 33 34 35 36 37 38 39 40 41 42
Columns 43 through 56
43 44 45 46 47 48 49 50 51 52 53 54 55 56
Columns 57 through 64
57 58 59 60 61 62 63 64
figure
imagesc(rampImage)
colormap(gray)
a=[1 2 ; 3 4]
a =
1 2
3 4
a(:)
ans =
1
3
2
4
eye(5)
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
who
Your variables are:
a b d f
ans c e rampImage
whos
Name Size Bytes Class Attributes
a 2x2 32 double
ans 5x5 200 double
b 1x5 40 double
c 1x7 56 double
d 1x6 48 double
e 10x1 80 double
f 15x1 120 double
rampImage 1x64 512 double
size(a)
ans =
2 2
help imread
IMREAD Read image from graphics file.
A = IMREAD(FILENAME,FMT) reads a grayscale or color image from the file
specified by the string FILENAME. If the file is not in the current
directory, or in a directory on the MATLAB path, specify the full
pathname.
The text string FMT specifies the format of the file by its standard
file extension. For example, specify 'gif' for Graphics Interchange
Format files. To see a list of supported formats, with their file
extensions, use the IMFORMATS function. If IMREAD cannot find a file
named FILENAME, it looks for a file named FILENAME.FMT.
The return value A is an array containing the image data. If the file
contains a grayscale image, A is an M-by-N array. If the file contains
a truecolor image, A is an M-by-N-by-3 array. For TIFF files containing
color images that use the CMYK color space, A is an M-by-N-by-4 array.
See TIFF in the Format-Specific Information section for more
information.
The class of A depends on the bits-per-sample of the image data,
rounded to the next byte boundary. For example, IMREAD returns 24-bit
color data as an array of uint8 data because the sample size for each
color component is 8 bits. See the Remarks section for a discussion of
bitdepths, and see the Format-Specific Information section for more
detail about supported bitdepths and sample sizes for a particular
format.
[X,MAP] = IMREAD(FILENAME,FMT) reads the indexed image in FILENAME into
X and its associated colormap into MAP. Colormap values in the image
file are automatically rescaled into the range [0,1].
[...] = IMREAD(FILENAME) attempts to infer the format of the file
from its content.
[...] = IMREAD(URL,...) reads the image from an Internet URL. The
URL must include the protocol type (e.g., "http://").
Remarks
Bitdepth is the number of bits used to represent each image pixel.
Bitdepth is calculated by multiplying the bits-per-sample with the
samples-per-pixel. Thus, a format that uses 8-bits for each color
component (or sample) and three samples per pixel has a bitdepth of 24.
Sometimes the sample size associated with a bitdepth can be ambiguous:
does a 48-bit bitdepth represent six 8-bit samples or three 16-bit
samples? The following format-specific sections provide sample size
information to avoid this ambiguity.
Format-Specific Information (Listed Alphabetically by Format)
BMP -- Windows Bitmap
Supported Compression Output
Bitdepths None RLE Class Notes
---------------------------------------------------------
1-bit x - logical
4-bit x x uint8
8-bit x x uint8
16-bit x - uint8 1 sample/pixel
24-bit x - uint8 3 samples/pixel
32-bit x - uint8 3 samples/pixel (1 byte padding)
CUR -- Cursor File
Supported Compression Output
Bitdepths None Compressed Class
--------------------------------------------------
1-bit x - logical
4-bit x - uint8
8-bit x - uint8
Special syntaxes:
[...] = IMREAD(...,IDX) reads in one image from a multi-image icon or
cursor file. IDX is an integer value that specifies the order that the
image appears in the file. For example, if IDX is 3, IMREAD reads the
third image in the file. If you omit this argument, IMREAD reads the
first image in the file.
[A,MAP,ALPHA] = IMREAD(...) returns the AND mask for the resource,
which can be used to determine transparency information. For cursor
files, this mask may contain the only useful data.
GIF -- Graphics Interchange Format
Supported Compression Output
Bitdepths None Compressed Class
---------------------------------------------
1-bit x - logical
2-to-8 bit x - uint8
Special syntaxes:
[...] = IMREAD(...,IDX) reads in one or more frames from a multiframe
(i.e., animated) GIF file. IDX must be an integer scalar or vector of
integer values. For example, if IDX is 3, IMREAD reads the third image
in the file. If IDX is 1:5, only the first five frames are returned.
[...] = IMREAD(...,'Frames',IDX) is the same as the syntax above except
that IDX can be 'all'. In this case, all of the frames are read and
returned in the order that they appear in the file.
Note: Because of the way GIF files are structured, all of the frames
must be read when a particular frame is requested. Consequently, it is
much faster to specify a vector of frames or 'all' for IDX than to call
IMREAD in a loop when reading multiple frames from the same GIF file.
HDF -- Hierarchical Data Format
Supported Raster image Raster image Output
Bitdepths with colormap without colormap Class Notes
------------------------------------------------------------
8-bit x x uint8
24-bit - x uint8 3 samples/pixel
Special Syntaxes:
[...] = IMREAD(...,REF) reads in one image from a multi-image HDF file.
REF is an integer value that specifies the reference number used to
identify the image. For example, if REF is 12, IMREAD reads the image
whose reference number is 12. (Note that in an HDF file the reference
numbers do not necessarily correspond with the order of the images in
the file. You can use IMFINFO to match up image order with reference
number.) If you omit this argument, IMREAD reads the first image in
the file.
ICO -- Icon File
See CUR.
JPEG -- Joint Photographic Experts Group
Note: IMREAD can read any baseline JPEG image as well as JPEG images
with some commonly used extensions.
Supported Compression Output
Bitdepths Lossy Lossless Class Notes
--------------------------------------------------------
8-bit x x uint8 Grayscale or RGB
12-bit x x uint16 Grayscale
16-bit - x uint16 Grayscale
36-bit x x uint16 RGB(Three 12-bit samples/pixel)
JPEG 2000 - Joint Photographic Experts Group 2000
Supported Compression Output
Bitdepths Lossy Lossless Class Notes
(per sample)
----------------------------------------------------------
1-bit x x logical Grayscale only
2- to 8-bit x x uint8 Grayscale or RGB
9- to 16-bit x x uint16 Grayscale or RGB
Note: Only 1- and 3-sample images are supported. Indexed JPEG 2000
images are not supported.
Special Syntaxes
[...] = IMREAD(..., 'Param1', value1, 'Param2', value2, ...) uses
parameter-value pairs to control the read operation. There are two
different parameters you can use:
Parameter name Value
-------------- -----
'ReductionLevel' A non-negative integer specifying reduction in
the resolution of the image. For a reduction
level 'L', the image resolution is reduced by a
factor of 2^L. Its default value is 0 implying
no reduction. The reduction level is limited by
the total number of decomposition levels as
provided by 'WaveletDecompositionLevels' field
in the structure returned from IMFINFO function.
'PixelRegion' {ROWS, COLS}. IMREAD returns the sub-image
specified by the boundaries in ROWS and COLS.
ROWS and COLS must both be two-element vectors
that denote the 1-based indices [START STOP]. If
'ReductionLevel' is greater than 0, then ROWS and
COLS are coordinates in the reduced-sized image.
PBM -- Portable Bitmap
Supported Raw ASCII (Plain) Output
Bitdepths Binary Encoded Class
----------------------------------------
1-bit x x logical
PCX -- Windows Paintbrush
Supported Output
Bitdepths Class Notes
----------------------------------------------
1-bit logical Grayscale only
8-bit uint8 Grayscale or indexed
24-bit uint8 RGB (8-bit samples)
PGM -- Portable Graymap
Supported Raw ASCII (Plain) Output
Bitdepths Binary Encoded Class
------------------------------------------------
up to 16-bit x - uint8
Arbitrary - x
PNG -- Portable Network Graphics
Supported Output
Bitdepths Class Notes
-------------------------------------------
1-bit logical Grayscale only
2-bit uint8 Grayscale only
4-bit uint8 Grayscale only
8-bit uint8 Grayscale or Indexed
16-bit uint16 Grayscale or Indexed
24-bit uint8 RGB (Three 8-bit samples/pixel)
48-bit uint16 RGB (Three 16-bit samples/pixel)
Special Syntaxes:
[...] = IMREAD(...,'BackgroundColor',BG) composites any transparent
pixels in the input image against the color specified in BG. If BG is
'none', then no compositing is performed. Otherwise, if the input image
is indexed, BG should be an integer in the range [1,P] where P is the
colormap length. If the input image is grayscale, BG should be an
integer in the range [0,1]. If the input image is RGB, BG should be a
three-element vector whose values are in the range [0,1]. The string
'BackgroundColor' may be abbreviated.
If the ALPHA output argument is used (see below), then BG defaults to
'none' if not specified by the user. Otherwise, if the PNG file
ontains a background color chunk, that color is used as the default
value for BG. If ALPHA is not used and the file does not contain a
background color chunk, then the default value for BG is 1 for indexed
images; 0 for grayscale images; and [0 0 0] for RGB images.
[A,MAP,ALPHA] = IMREAD(...) returns the alpha channel if one is
present; otherwise ALPHA is []. Note that MAP may be empty if the file
contains a grayscale or truecolor image.
PPM -- Portable Pixmap
Supported Raw ASCII (Plain) Output
Bitdepths Binary Encoded Class
------------------------------------------------
up to 16-bit x - uint8
Arbitrary - x
RAS -- Sun Raster
Supported Output
Bitdepths Class Notes
----------------------------------------------------
1-bit logical Bitmap
8-bit uint8 Indexed
24-bit uint8 RGB (8-bit samples)
32-bit uint8 RGB with Alpha (8-bit samples)
TIFF -- Tagged Image File Format
Supported Compression Output
Bitdepths None Packbits CCITT RGB ICCLAB CIELAB CMYK Class Notes
-----------------------------------------------------------------------
1-bit x x x - - - - logical
8-bit x x - - - - - uint8
12-bit - - - - - - - uint16 Grayscale
or Indexed
16-bit - - - - - - - uint16 Grayscale
or Indexed
24-bit x x - x x x - uint8 3 samples
32-bit - - - - - - x uint8 4 samples
36-bit - - - x - - - uint16 3 samples
48-bit - - - x x x - uint16 3 samples
64-bit - - - - - - x double 4 samples
NOTE: IMREAD supports 8-bit integral and 32-bit floating point tiled
TIFF images, with any compression and colorspace combination listed
above, and 32-bit IEEE floating point images.
Special Syntaxes:
A = IMREAD(...) returns color data that uses the RGB, CIELAB, ICCLAB,
or CMYK color spaces. If the color image uses the CMYK color space, A
is an M-by-N-by-4 array.
[...] = IMREAD(..., 'Param1', value1, 'Param2', value2, ...) uses
parameter-value pairs to control the read operation. There are three
different parameters you can use:
Parameter name Value
-------------- -----
'Index' A positive integer specifying which image to read in
a multi-image TIFF file. For example, if 'Index' is
3, IMREAD reads the third image in the file.
'Info' A structure array; the output of IMFINFO. When
reading images from a multi-image TIFF file, passing
the output of IMFINFO as the 'Info' parameter helps
IMREAD locate the images in the file more quickly.
'PixelRegion' {ROWS, COLS}. IMREAD returns the sub-image
specified by the boundaries in ROWS and COLS. ROWS
and COLS must be either two- or three-element
vectors. If two elements are provided, they denote
the 1-based indices [START STOP]. If three elements
are provided, the indices [START INCREMENT STOP]
allow image downsampling.
XWD -- X Window Dump
Supported Output
Bitdepths ZPixmaps XYBitmaps XYPixmaps Class
--------------------------------------------------
1-bit x - x logical
8-bit x - - uint8
See also imfinfo, imwrite, imformats, fread, image, double, uint8.
Reference page in Help browser
doc imread
im=imread('flower.tiff')
im(:,:,1) =
Columns 1 through 17
91 93 95 96 95 96 97 96 96 89 89 85 84 83 83 80 79
88 91 92 93 94 95 94 94 93 91 90 85 83 83 81 77 73
...
I deleted the output from here to the end of the image, as it is too big... (- Erik).
26 25 25 28 30 28 28
im=imread('flower.tiff');
imagesc(im)
size(im)
ans =
333 500 3
im(1,1,:)
ans(:,:,1) =
91
ans(:,:,2) =
112
ans(:,:,3) =
45
im(1,1,:)/256
ans(:,:,1) =
0
ans(:,:,2) =
0
ans(:,:,3) =
0
double(im(1,1,:))/256
ans(:,:,1) =
0.3555
ans(:,:,2) =
0.4375
ans(:,:,3) =
0.1758
lookfor fourier
fft - Discrete Fourier transform.
fft2 - Two-dimensional discrete Fourier Transform.
fftn - N-dimensional discrete Fourier Transform.
ifft - Inverse discrete Fourier transform.
ifft2 - Two-dimensional inverse discrete Fourier transform.
ifftn - N-dimensional inverse discrete Fourier transform.
diary off