-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring2data.m
More file actions
28 lines (21 loc) · 912 Bytes
/
string2data.m
File metadata and controls
28 lines (21 loc) · 912 Bytes
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
function [ X, count, label] = string2data( string, baseline, increment )
% Generate a dataset use a string as its shape
% Get the image of the string
img = 1 - text2im(string)';
num_points = 1000 * length(string);
% Generate a number of datapoint
[width, height] = size(img);
X1 = rand(num_points, 1) .* width;
X2 = rand(num_points, 1) .* height;
X = [X1 X2];
% Generate the count of each data points according to its position
roundx = max(round(X), 1);
label = diag(img(roundx(:, 1), height + 1 - roundx(:, 2)));
count = [baseline * ones(num_points, 1), poissrnd(baseline + increment * label, num_points, 1)];
% Plot the dataset
plot(X(label==1, 1), X(label==1, 2), 'b.', X(label==0, 1), X(label==0, 2), 'c.')
axis equal
axis([0, width, 0, height])
legend('Poisson(115)', 'Possion(100)')
label = 2 .* label - 1;
end