DIP/Matlab

[Ch4] Image Display

jeong_reneer 2022. 1. 29. 08:33

4.1 Introduction

imshow function

Spatial resolution and Quantization

Image quality 

Image attributes

 

4.2 The imshow function

1) Greyscale images

x : matrix of type uint8 (int bw 0 ~ 255) → imshow(x) : display x as greyscale img

c : matrix of type double → (1) or (2)

 

(1) Convert to type uint8 and then display

(2) Display the matrix directly

imshow(c) : display c of type double as greyscale img if elements are bw 0~1

imshow(cd) : every pixel which has value greater than or equal to 1 (in fact min is 21) will be displayed as white

>> c=imread('caribou.tif');
>> cd=double(c);
>> imshow(c),figure,imshow(cd)

 

Need to Scale values bw 0~1

Dividing double type image

cd/512 : all values are bw 0 ~ 0.5  → brightest pixel is a mid-grey(0.5)

cd/128 : all values are bw 0 ~ 2     → pixel value = 1~2 will be displayed as white(1)

>> imshow(cd/512)
>> imshow(cd/128)

 

② Converting original img to double (correct scaling)

im2double(c) : all values are bw 0 ~ 1 → correct img

>> cd=im2double(c);
>> imshow(cd)
function change numeric data type  change numeric values
double O X
im2double O O

 

+) Convert back to type uint8

im2uint8 : take other data type as input, and always return a correct result (0~1)

>> c2=uint8(255*cd);
>> c3=im2uint8(cd); # preferred

 

 

2) Binary images

Binary img : only 2 values (0 and 1)

BUT MATLAB does not have a binary data type

 

(1) Logical flag : uint8 values as 0 and 1 = logical data

Relational operations (==, <, >, yes/no answer operators)

>> c=imread('caribou.tif');
>> cl=c>120;
>> whos
    cl 256x256 65536 uint8 array (logical)
>> imshow(c1)

>> cl = +cl;
>> whos
    cl 256x256 65536 uint8 array
>> imshow(c1)

(b) uint8 : 0(black) ~ 255(white) → 1 is very dark grey (almost black)

 

+) Get back to viewable img

>> imshow(logical(cl))
>> imshow(double(cl))

 

 

 

4.3 Bit planes

Greyscale images (Breaking img up into their bit-planes) → A sequence of binary images

grey value of each pixel of an 8-bit img 8-bit binary word

>> c=imread('cameraman.tif');
>> cd=double(c);

>> c0=mod(cd,2);
>> c1=mod(floor(cd/2),2);
>> c2=mod(floor(cd/4),2);
>> c3=mod(floor(cd/8),2);
>> c4=mod(floor(cd/16),2);
>> c5=mod(floor(cd/32),2);
>> c6=mod(floor(cd/64),2);
>> c7=mod(floor(cd/128),2);

 

c0  (0th bit-plane) = Least significant bit-plane : consisted of the last bit of each value

= (to all intents and purposes) a random array

 

c7 (7th bit-plane) = Most significant bit-plane : consisted of the first bit of each value

= threshold of img at level 127

>> ct=c>127;
>> all(c7(:)==ct(:))
ans =
    1

 

+) Recover and display original img

>> cc=2*(2*(2*(2*(2*(2*(2*c7+c6)+c5)+c4)+c3)+c2)+c1)+c0;
>> imshow(uint8(cc))

 

 

1) Bit plane of digital image

: a set of bits corresponding to a given bit position in each of binary numbers representing img 

8-bits bit plane (0~255) 에서 하위 비트로 갈수록 이미지가 원래 이미지와 다르게 변해 알아볼 수 없어짐

 

2) Bit masking

- Reset (0) : AND with 0

- Set (1) : OR with 1

- Toggle (Invert) : XOR with 1

- 원하는 비트의 정보 get : 해당 비트에 AND with 1 

    Ex) 0b1010 AND 0b1111 = 0b1010 

 

3) Bit slicing

 

4) Bit combining

 

 

 

4.4 Spatial Resolution

1) Spatial Resolution

: the density of pixels over the image

The greater spatial resolution, the more pixels are used to display img

 

2) imresize

x : 256x256 8-bit greyscale img 

imresize(x, 1/2) → halve the size of img

>> imresize(x,1/2);

 

imresize(x, 2) → all the pixels are repeated

imresize(imresize(x,  1/2), 2) → same size as original img, But with half the resolution in each direction

Effective resolution of new img : 128x128 

>> imresize(imresize(x,1/2),2);

 

Command Effective resolution
imresize(imresize(x,1/2),2); 128 x 128
imresize(imresize(x,1/4),4); 64 x 64
imresize(imresize(x,1/8),8); 32 x 32
imresize(imresize(x,1/16),16; 16 x 16
imresize(imresize(x,1/32),32); 8 x 8

 

Decreasing Resolution Increasing effects of blockiness or pixelization

blockiness : 압축된 이미지에서 나타나는 타일과 같은 현상 (인공적 결함)

pixelization : 모자이크 현상