clear all;
clc;

%% images I/O on file
% Load the image from file into the X matrix
X = imread('satellite_gray.jpg');

% show the image
figure;
imshow(X);

% Images are matrices, but not in double
whos
% uint8: 8 bit -> 0..255
% elements greater than 255 are shown as white
imshow(X*2)
% elements smaller than 0 are shown as black
imshow(X-150)

% Images can be black-and-white (binary) images (0 black, 1 white)
imshow(X<80)

% Store an image in a file
imwrite(X<80, 'sat_threshold.png');
% Image representation format can be specified.
% When no explicit options are provided, the most cheap format is chosen
T = imread('sat_threshold.png');
whos

% Conversion
X = imread('teethwhitening_Woman_Smile_small.jpg');
imshow(X);
whos
T = rgb2gray(X);
imshow(T);
whos

%% Topology
% Return a structure with the list of the connected components wrt the specified neighborhood relationship.
X = T > 220;
cc = bwconncomp(X,4);
