-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimshow.sci
88 lines (76 loc) · 3.18 KB
/
imshow.sci
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (C) 2015 - IIT Bombay - FOSSEE
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
// Organization: FOSSEE, IIT Bombay
// Email: [email protected]
function[] =imshow(Image,varargin)
// Used to view an image
//
// Calling Sequence
// src = imshow(Image);
// src = imshow(Image,winName);
// src = imshow(Image,winName,winSize);
//
// Parameters
// Image : Input image
// winName= Name of the image window specified as a string.
// winSize=Size of the image window specified as [rows,cols]
//
// Examples
// src = imread('images/lena.jpeg');
// imshow(src);
Image=mattolist(Image); //retrieving list and creating 3 dimensional matrix out of it
dimensions=size(Image) //convert hyper matrix to list
[lhs rhs]= argn(0);
if lhs>1
error(msprintf("Too many outut arguments"));
end
if rhs<1
error(msprintf("Not enough input arguments"));
end
if dimensions==3 then
[c d]=size(Image(1));
r=matrix(Image(1),c,d);
g=matrix(Image(2),c,d);
b=matrix(Image(3),c,d);
z(:,:,1)=r;
z(:,:,2)=g;
z(:,:,3)=b;
[NumberOfRows NumberOfColumns NumberOfChannels] = size(z);
winSize=[(1080/NumberOfRows)*NumberOfRows,(1920/NumberOfColumns)*NumberOfColumns];
NumberOfPixels = NumberOfRows * NumberOfColumns;
MaxGrayValue = 2 ^ 8 - 1;
ColorMap = double(matrix(z, NumberOfPixels, NumberOfChannels)) ...
/ MaxGrayValue;
Img = matrix(1 : NumberOfPixels, NumberOfRows, NumberOfColumns);
elseif dimensions==1 then // its a single channel image
MaxUInt8 = 8; //declaring MaxUInt8
depth = getDepth(Image(1));
if (strcmp(depth,'CV_16U')==0 | strcmp(depth,'CV_64F')==0 ) //if its a 16 bit image or a 64 bit float image
Image(1) = convert(Image(1),'CV_8U',255,0); //we'll convert it to 8 bit unsigned int
// if its a 64 bit float image, we assume that
//it has normalized for the range [0,1]
end
[c d]=size(Image(1));
Img=matrix(Image(1),c,d);
[NumberOfRows NumberOfColumns]=size(Img);
winSize=[(1080/NumberOfRows)*NumberOfRows,(1920/NumberOfColumns)*NumberOfColumns];
MaximumGrayValue = 2^MaxUInt8 -1;
ColorMap = graycolormap(double(MaximumGrayValue + 1));
end;
winName="Title";
if rhs>1 then
winName=varargin(1);
if type(winName) ~= 10
error(msprintf("Figure Name must be a string"));
end
if rhs==3
winSize=varargin(2);
end
end
show(Img,ColorMap,winName,winSize);
endfunction