Skip to content

Commit

Permalink
workaround for matlabs image+colorbar bug
Browse files Browse the repository at this point in the history
* workaround for matlabs image+colorbar bug
* clean-up
  • Loading branch information
grinsted committed Jul 11, 2014
1 parent bba1e05 commit 93d6cb7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 37 deletions.
11 changes: 6 additions & 5 deletions demobatura.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
%visualize the results
%turn the intensity image into an RGB image
%so that it does not interfere with colorbar:
imshow(repmat(A,[1 1 3]))
image(repmat(A,[1 1 3]),'CDataMapping','scaled') %the cdatamapping is a workaround for a bug in R2014+
axis equal off tight ij
hold on

signal2noise=C(:,1)./C(:,2);
Expand All @@ -45,9 +46,9 @@
quiver(uvA(keep,1),uvA(keep,2),V(keep,1)./Vn(keep),V(keep,2)./Vn(keep),0.2,'k') %arrows show direction.
colormap jet
caxis([0 200])
hcb=colorbar('southoutside');
if ~verLessThan('matlab', '8.4.0')
set(hcb,'limits',caxis) %workaround for a critical colorbar bug in Matlab 2014b preview... TODO: check if bug present in final release
end
colorbar('southoutside');
% if ~verLessThan('matlab', '8.4.0')
% set(hcb,'limits',caxis) %workaround for a critical colorbar bug in Matlab 2014b preview... TODO: check if bug present in final release
% end


17 changes: 11 additions & 6 deletions demobindschadler.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
%% IMCORR Bindschadler Ice Stream example
%
% The IMCORR feature tracking software comes with two example image pairs.
% These are Landsat TM subscenes of a portion of Ice Stream D in West
% Antarctica (Now know as Bindschadler Ice Stream). This page shows how
% these can be tracked using the ImGRAFT toolbox.
%


datafolder=downloadDemoData('imcorr');

Expand All @@ -15,7 +23,8 @@
[dxy,C]=templatematch(A,B,uvA,whtemplate,whsearch,super,[0 0],{'1987' '1989'},'myncc');

close all
imshow(repmat(A,[1 1 3]))
image(repmat(A,[1 1 3]),'CDataMapping','scaled') %the cdatamapping is a workaround for a bug in R2014+)
equal off tight ij
hold on
signal2noise=C(:,1)./C(:,2);
keep=(signal2noise>2)&(C(:,1)>.5);
Expand All @@ -25,8 +34,4 @@
quiver(uvA(keep,1),uvA(keep,2),V(keep,1)./Vn(keep),V(keep,2)./Vn(keep),0.2,'k') %arrows show direction.
colormap jet
caxis([0 400])
hcb=colorbar('southoutside');
if ~verLessThan('matlab', '8.4.0')
set(hcb,'limits',caxis) %workaround for a critical colorbar bug in Matlab 2014b preview... TODO: check if bug present in final release
end

colorbar('southoutside');
10 changes: 2 additions & 8 deletions demoengabreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@

%plot candidate points on map view
figure;
image(dem.x,dem.y,dem.rgb)
image(dem.x,dem.y,dem.rgb,'CDataMapping','scaled') %the cdatamapping is a workaround for a bug in R2014+)
axis equal xy off tight
hold on
Vn=sqrt(sum(V(:,1:2).^2,2));
Expand All @@ -218,9 +218,6 @@
caxis([0 1])
colormap jet
hcb=colorbar('southoutside');
if ~verLessThan('matlab', '8.4.0')
set(hcb,'limits',caxis); %workaround for a bug in Matlab 2014b preview
end
plot(camA.xyz(1),camA.xyz(2),'r+')
title('Velocity in metres per day')

Expand All @@ -238,7 +235,7 @@


figure
image(dem.x,dem.y,dem.rgb)
image(dem.x,dem.y,dem.rgb,'CDataMapping','scaled') %the cdatamapping is a workaround for a bug in R2014+
axis equal xy off tight

hold on
Expand All @@ -249,9 +246,6 @@
caxis([0 1])
colormap jet
hcb=colorbar('southoutside');
if ~verLessThan('matlab', '8.4.0')
set(hcb,'limits',caxis); %workaround for a bug in Matlab 2014b preview
end

plot(camA.xyz(1),camA.xyz(2),'r+')
title('Velocity along slope direction in metres per day')
Expand Down
33 changes: 15 additions & 18 deletions templatematch.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,23 @@
else
showprogress=[];
end
end

%INITIALIZE PROGRESS FIGURE....
if ~isempty(showprogress)
else
if ~iscell(showprogress)
if isnumeric(showprogress)
showprogress=arrayfun(@num2str,showprogress,'uniformoutput',false);
else
showprogress=num2cell(showprogress);
end
end
end

%INITIALIZE PROGRESS FIGURE....
if ~isempty(showprogress)
fh=figure;
set(fh,'name','Templatematch progress','NumberTitle','off');
clf
set(fh,'renderer','opengl')
set(fh,'name','Templatematch progress','NumberTitle','off','renderer','opengl')
hax=axes('pos',[0 0.01 0.5 0.95]);
showimg(A);
text(0.5,1,showprogress{1},'units','normalized','vert','bottom','fontname','courier','horiz','center')
%plot(points(:,1),points(:,2),'b+','markersize',2)
cc=zeros(2,size(points,1));
hscatterA=mesh(points(:,[1 1])',points(:,[2 2])',zeros(2,size(points,1)),'mesh','column','marker','.','markersize',5,'cdata',cc); %bizarrely much faster than scatter
colormap jet
Expand Down Expand Up @@ -311,30 +309,29 @@
end
A=A./diff(R);

function showimg(A)
function showimg(A) %replacement for imshow. -faster and no reliance on image processing toolbox
if isfloat(A)
A=uint8(A*255);
else
if strcmp(class(A),'uint16')
A=uint8(A./256);
end
end
if size(A,3)<3
A=repmat(A,[1 1 3]);
end
[X,Y]=meshgrid([0.5 size(A,2)+0.5],[0.5 size(A,1)+0.5]);

% screensize=get(0,'ScreenSize');
% downsample=ceil(size(A,1)*2/screensize(3));
% if downsample>1
% A=imresize(A,1/downsample); %TODO:remove dependency!
% end
surface(X,Y,zeros(size(X))-1,A,'EdgeColor','none','FaceColor','texturemap');
if size(A,3)<3
A=repmat(A,[1 1 3]);
end
[X,Y]=meshgrid([0.5 size(A,2)+0.5],[0.5 size(A,1)+0.5]);
surface(X,Y,zeros(size(X))-1,A,'EdgeColor','none','FaceColor','texturemap'); %it is much faster than using an image! (Bizarrely)
axis off tight equal image ij;
zlim([-1.1 .1]) %critical as otherwise matlabs clipping plane will throw out points with z=0 in older versions of matlab.
zlim([-1.1 .1]) %critical as otherwise matlabs clipping plane will throw out points with z=0 in older versions of matlab. BUG.
hold on
% plot(mean(X(:)),mean(Y(:)),'r.','markersize',10)


%it is much faster as a texture map! (Bizarrely)



0 comments on commit 93d6cb7

Please sign in to comment.