-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadMyImage.m
37 lines (32 loc) · 915 Bytes
/
readMyImage.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [out] = readMyImage(I)
%
% This function is able to read an image and automatically detect
% if the image is in color or grayscale. If the image is in color,
% the output will be same version but in grayscale. if the image is
% in grayscale, the output is the same image.
%
% ---- Oscar Castro, 10 05 2021
%
% ---------- Example ----------
%
% clear all; close all; clc;
%
% image = "img\lenna.tif";
% I = imread(image);
%
% readMyImage(I);
% ===================================================================== %
% Get channels of 'I'
[~,~,chan]=size(I);
% Detect if 'I' is in color and automatically transform it in grayscale
if (chan == 3)
out = rgb2gray(I);
disp('I is coloured');
elseif (chan == 1)
out = I;
disp('I is in grayscale');
end
figure,
subplot(1,2,1); imshow(I);title('Original Image');
subplot(1,2,2); imshow(uint8(out));title('readMyImage');
end