-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateImage.m
45 lines (40 loc) · 1.03 KB
/
CreateImage.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
38
39
40
41
42
43
44
45
clc;
fileID = fopen('MyProgram.ll','r');
readContent = fread(fileID);
m = size(readContent);
[w, h] = leastDiffFactor(m(1));
content = transpose(readContent);
imageMatrix = reshape(content, [h, w]);
image = mat2gray(imageMatrix);
RGB = repmat(image, [1, 1, 3]);
imshow(RGB);
imwrite(RGB,'MyProgram.png');
function [num1, num2] = leastDiffFactor(k)
factors = factor2(k);
prevDiff = 100000000;
for i = 1:length(factors)
tempNum1 = factors(i);
tempNum2 = int32(k/tempNum1);
diff = abs(tempNum1 - tempNum2);
if(diff <= prevDiff)
prevDiff = diff;
num1 = tempNum1;
num2 = tempNum2;
end
end
%midFactor = factors(int32(floor(length(factors)/2)));
%num1 = midFactor;
%num2 = int32(k/num1);
end
function a = factor2(k)
if ~isinteger(k)|| k < 1
error('Valid only for positive integers.');
end
a = 1:floor(k/2);
tmp = k./a;
tmp = isinteger(tmp);
a = [a(tmp),k];
function a = isinteger(k)
a = k == floor(k);
end
end