4. Querying a pixel info
● Because the image itself is an array, we can check the values it is storing.
For example, if we want to know the values of the pixel at (350, 250):For example, if we want to know the values of the pixel at (350, 250):
● >> img(350,250,:)
● ans(:,:,1) = 157
● ans(:,:,2) = 70
● ans(:,:,3) = 0
5. rgb2ind()
● "Indexed color saves a lot of memory, storage space, and transmission
time: using truecolor, each pixel needs 24 bits, or 3 bytes. A typicaltime: using truecolor, each pixel needs 24 bits, or 3 bytes. A typical
640x480 VGA resolution truecolor uncompressed image needs 640x480x3
= 921,600 bytes (900 KiB). Limiting the image colors to 256, every pixel
needs only 8 bits, or 1 byte each, so the example image now needs only
640x480x1 = 307,200 bytes (300 KiB), plus 256x3 = 768 additional bytes to
store the palette map in itself (assuming RGB), approx. one third of the
original size."
11. Creating grayscale image: We're going to create two
grayscale images of size 320×240,320×240,one with pixels
all black and the other one all white:
h = 240;
w = 320;
white = uint8(255*ones(h,w));
black = uint8(zeros(h,w));
figure;figure;
subplot(121);
imshow(white);
subplot(122);
imshow(black);
12. Class - Data Type: There are one thing to keep in mind when we process
images: data type. Is my image in uint8or double? One of the most frequent
issues caused by the data type is imshow(). We converted the image to double
to do something with the image, and now we want to draw it
● img = imread('cameraman.tif');
● img_d = double(img);● img_d = double(img);
● % ... played with the image, now we want to display it
● imshow(img_d);
Result is white image rather than original image
The imshow() has two function overloading. It takes image with type uint8 as it ranges
between [0, 255], and takes image with type double as it ranges between [0, 1]. So, in our
case, every pixel with over 1 is considered saturated, and that's why we got white cameraman.
14. Extracting bit-plane from Grayscale image With mod() operation, we can extract a bit-
plane image. The mod(img,2) gives us either 0 or 1
img = imread('cameraman.tif');
img = double(img);
bp0 = mod(img,2);
imshow(bp0);
title('bit-plane 0');
bit-plane 0 bit-plane 1
title('bit-plane 0');