Last active
August 29, 2015 14:25
-
-
Save jnkather/401a392de8203d11f3dc to your computer and use it in GitHub Desktop.
Create a random dataset and show the points as trees.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% requires showTree.m | |
% --- create data | |
nObj = 100; | |
rng(3); | |
scale = 100; | |
data = rand(nObj,2)*scale; | |
% --- set up parameters | |
saveOutput = true; | |
imgResolution = '-r300'; | |
saveDir = 'output/'; | |
% % --- naively show data | |
figure(); | |
scatter(data(:,1),data(:,2),25,[0 0 0],'filled'); | |
set(gcf,'Color','w'); | |
axis equal tight; | |
axScale = axis(); | |
axis off | |
if saveOutput | |
print(gcf,[saveDir, '01_data_sparse','.png'],'-dpng',imgResolution) | |
end | |
% % --- show data as trees | |
figure(); | |
hold on | |
for i=1:size(data,1) | |
showTree(data(i,1),data(i,2),200); | |
end | |
set(gcf,'Color','w'); | |
axis equal tight; | |
axScale = axis(); | |
axis off | |
if saveOutput | |
print(gcf,[saveDir, '01_data_trees','.png'],'-dpng',imgResolution) | |
end | |
% % --- show different patterns as trees | |
nTrees = 64; % has to be a square! | |
figure(); | |
subplot(2,2,1); | |
rng(5) | |
datacompare = rand(nTrees,2)*scale; | |
hold on | |
for i=1:size(datacompare,1) | |
showTree(datacompare(i,1),datacompare(i,2),200); | |
end | |
axis equal tight; | |
axis off | |
subplot(2,2,2); | |
rng(8) | |
datacompare = rand(nTrees,2)*scale; | |
hold on | |
for i=1:size(datacompare,1) | |
showTree(datacompare(i,1),datacompare(i,2),200); | |
end | |
axis equal tight; | |
axis off | |
subplot(2,2,3); | |
rng(10) | |
[xx yy] = meshgrid(linspace(1,100,sqrt(nTrees))); | |
datacompare(:,1) = xx(:); datacompare(:,2) = yy(:); | |
hold on | |
for i=1:size(datacompare,1) | |
showTree(datacompare(i,1),datacompare(i,2),200); | |
end | |
axis equal tight; | |
axis off | |
subplot(2,2,4); | |
rng(15) | |
datacompare = rand(round(nTrees*0.8),2)*scale/3+scale/3; | |
datacompare = [datacompare; rand(round(nTrees*0.2),2)*scale]; | |
hold on | |
for i=1:size(datacompare,1) | |
showTree(datacompare(i,1),datacompare(i,2),200); | |
end | |
axis equal tight; | |
axis off | |
% decorations | |
set(gcf,'Color','w'); | |
if saveOutput | |
print(gcf,[saveDir, 'trees_collection','.png'],'-dpng',imgResolution) | |
end | |
% % --- show different patterns as trees - 2D histogram | |
nTrees = 64; % has to be a square! | |
nBins = 8; | |
figure(); | |
subplot(2,2,1); | |
rng(5) | |
datacompare = rand(nTrees,2)*scale; | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
surf(xgrid,ygrid,zcounts,'LineStyle','-'); | |
view(-90,90) | |
axis equal tight; | |
axis off | |
cvalue = caxis() | |
subplot(2,2,2); | |
rng(8) | |
datacompare = rand(nTrees,2)*scale; | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
surf(xgrid,ygrid,zcounts,'LineStyle','-'); | |
view(-90,90) | |
axis equal tight; | |
axis off | |
caxis(cvalue) | |
subplot(2,2,3); | |
rng(10) | |
[xx yy] = meshgrid(linspace(1,100,sqrt(nTrees))); | |
datacompare(:,1) = xx(:); datacompare(:,2) = yy(:); | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
surf(xgrid,ygrid,zcounts,'LineStyle','-'); | |
view(-90,90) | |
axis equal tight; | |
axis off | |
caxis(cvalue) | |
subplot(2,2,4); | |
rng(15) | |
datacompare = rand(round(nTrees*0.8),2)*scale/3+scale/3; | |
datacompare = [datacompare; rand(round(nTrees*0.2),2)*scale]; | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
surf(xgrid,ygrid,zcounts,'LineStyle','-'); | |
view(-90,90) | |
axis equal tight; | |
axis off | |
caxis(cvalue) | |
% decorations | |
set(gcf,'Color','w'); | |
if saveOutput | |
print(gcf,[saveDir, 'trees_collection-histo','.png'],'-dpng',imgResolution) | |
end | |
% % --- show different patterns as trees - 1D histogram | |
nTrees = 64; % has to be a square! | |
nBins = 8; | |
histBins = cvalue(1):cvalue(2); | |
figure(); | |
subplot(2,2,1); | |
rng(5) | |
datacompare = rand(nTrees,2)*scale; | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
[counts,centers] = hist(zcounts(:),histBins); | |
bar(centers,counts,'LineWidth',1) | |
subplot(2,2,2); | |
rng(8) | |
datacompare = rand(nTrees,2)*scale; | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
[counts,centers] = hist(zcounts(:),histBins); | |
bar(centers,counts,'LineWidth',1) | |
subplot(2,2,3); | |
rng(10) | |
[xx yy] = meshgrid(linspace(1,100,sqrt(nTrees))); | |
datacompare(:,1) = xx(:); datacompare(:,2) = yy(:); | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
[counts,centers] = hist(zcounts(:),histBins); | |
bar(centers,counts,'LineWidth',1) | |
subplot(2,2,4); | |
rng(15) | |
datacompare = rand(round(nTrees*0.8),2)*scale/3+scale/3; | |
datacompare = [datacompare; rand(round(nTrees*0.2),2)*scale]; | |
xgrid = linspace(0,scale,nBins); | |
ygrid = linspace(0,scale,nBins); | |
% use interpolation to create a native 2D histogram | |
xcounts = interp1(xgrid,1:numel(xgrid),datacompare(:,1),'nearest')'; | |
ycounts = interp1(ygrid,1:numel(ygrid),datacompare(:,2),'nearest')'; | |
zcounts = accumarray([xcounts' ycounts'], 1, [nBins nBins]); | |
% show | |
[counts,centers] = hist(zcounts(:),histBins); | |
bar(centers,counts,'LineWidth',1) | |
% decorations | |
set(gcf,'Color','w'); | |
if saveOutput | |
print(gcf,[saveDir, 'trees_collection-histo-histo','.png'],'-dpng',imgResolution) | |
end | |
% --- count neighbors, circles | |
nTrees = 64; % has to be a square! | |
radiusOfInterest = 25; | |
figure(); | |
subplot(2,2,1); | |
rng(5) | |
datacompare = rand(nTrees,2)*scale; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
viscircles(datacompare,repmat(radiusOfInterest,size(datacompare,1),1),'EdgeColor','k','LineWidth',1); | |
hold on | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
cvalue = caxis(); | |
cvalue(2) = round(cvalue(2)*1.2); | |
caxis(cvalue); | |
axis off | |
subplot(2,2,2); | |
rng(8) | |
datacompare = rand(nTrees,2)*scale; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
viscircles(datacompare,repmat(radiusOfInterest,size(datacompare,1),1),'EdgeColor','k','LineWidth',1); | |
hold on | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
caxis(cvalue) | |
axis off | |
subplot(2,2,3); | |
rng(10) | |
[xx yy] = meshgrid(linspace(1,100,sqrt(nTrees))); | |
datacompare(:,1) = xx(:); datacompare(:,2) = yy(:); | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
viscircles(datacompare,repmat(radiusOfInterest,size(datacompare,1),1),'EdgeColor','k','LineWidth',1); | |
hold on | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
caxis(cvalue) | |
axis off | |
subplot(2,2,4); | |
rng(15) | |
datacompare = rand(round(nTrees*0.8),2)*scale/3+scale/3; | |
datacompare = [datacompare; rand(round(nTrees*0.2),2)*scale]; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
viscircles(datacompare,repmat(radiusOfInterest,size(datacompare,1),1),'EdgeColor','k','LineWidth',1); | |
hold on | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
caxis(cvalue) | |
axis off | |
% decorations | |
set(gcf,'Color','w'); | |
if saveOutput | |
print(gcf,[saveDir, 'trees_collection-neighbors-circ','.png'],'-dpng',imgResolution) | |
end | |
% --- count neighbors, no circles | |
nTrees = 64; % has to be a square! | |
radiusOfInterest = 25; | |
figure(); | |
subplot(2,2,1); | |
rng(5) | |
datacompare = rand(nTrees,2)*scale; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
caxis(cvalue); | |
axis off | |
subplot(2,2,2); | |
rng(8) | |
datacompare = rand(nTrees,2)*scale; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
caxis(cvalue) | |
axis off | |
subplot(2,2,3); | |
rng(10) | |
[xx yy] = meshgrid(linspace(1,100,sqrt(nTrees))); | |
datacompare(:,1) = xx(:); datacompare(:,2) = yy(:); | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
caxis(cvalue) | |
axis off | |
subplot(2,2,4); | |
rng(15) | |
datacompare = rand(round(nTrees*0.8),2)*scale/3+scale/3; | |
datacompare = [datacompare; rand(round(nTrees*0.2),2)*scale]; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
scatter(datacompare(:,1),datacompare(:,2),50,neighbors,'filled'); | |
colormap(parula()) | |
axis equal tight; | |
caxis(cvalue) | |
axis off | |
% decorations | |
set(gcf,'Color','w'); | |
if saveOutput | |
print(gcf,[saveDir, 'trees_collection-neighbors-nocirc','.png'],'-dpng',imgResolution) | |
end | |
%% neighbors, no circles, histogram of distances | |
nTrees = 64; % has to be a square! | |
radiusOfInterest = 25; | |
histBins = cvalue(1):cvalue(2); | |
figure(); | |
subplot(2,2,1); | |
rng(5) | |
datacompare = rand(nTrees,2)*scale; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
[counts,centers] = hist(neighbors,histBins); | |
bar(centers,counts,'LineWidth',1) | |
subplot(2,2,2); | |
rng(8) | |
datacompare = rand(nTrees,2)*scale; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
[counts,centers] = hist(neighbors,histBins); | |
bar(centers,counts,'LineWidth',1) | |
subplot(2,2,3); | |
rng(10) | |
[xx yy] = meshgrid(linspace(1,100,sqrt(nTrees))); | |
datacompare(:,1) = xx(:); datacompare(:,2) = yy(:); | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
[counts,centers] = hist(neighbors,histBins); | |
bar(centers,counts,'LineWidth',1) | |
subplot(2,2,4); | |
rng(15) | |
datacompare = rand(round(nTrees*0.8),2)*scale/3+scale/3; | |
datacompare = [datacompare; rand(round(nTrees*0.2),2)*scale]; | |
[idx, dist] = rangesearch(datacompare,datacompare,radiusOfInterest); | |
neighbors = zeros(size(datacompare,1),1); | |
for i=1:size(datacompare,1) | |
neighbors(i) = numel(cell2mat(idx(i))); | |
end | |
% show | |
[counts,centers] = hist(neighbors,histBins); | |
bar(centers,counts,'LineWidth',1) | |
% decorations | |
set(gcf,'Color','w'); | |
if saveOutput | |
print(gcf,[saveDir, 'trees_collection-neighbors-hist','.png'],'-dpng',imgResolution) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment