paths = {'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\a\',... 'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\b\',... 'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\c\',... 'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\a_alt\',... 'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\a\',... 'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\b\',... 'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\c\',... 'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\d\'}; fontSize = 18;%font size in figs lineWidth = 3;%line widths in figs (if you have lines aspectRatio = 1;%aspect ratio of figs (may be irrelevant with zratio below) zratio = 150;%aspect ratio of z axis to others (typically nm, while others um, so quite high) lightStyle = 'gouraud';%the FaceLighting option in surf to use %%% To change colormap of 2D plots, find line 'colormap jet' and change %%% 'jet' to whatever you like viewEl = [45:5:55];%list of view elevations to save for each image viewAz = [45:5:55];%similar for azimuth zLimits = [-2000,100];%typical values for surface plot z limits, 2um deep, allow 100nm above surface cropIms = {5,0,643,543,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\a\profile2.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\a\pow4pol2.asc';... 5,0,721,492,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\b\profile4.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\b\pow4pol4.asc';... 5,0,706,498,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\c\profile6.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\c\pow4pol6.asc';... 5,0,725,462,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\a_alt\profile8.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 4\a_alt\pow4pol8.asc';... 5,0.96,661,528,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\a\profile60.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\a\zescope\inv60.asc';... 5,0.96,692,525,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\b\profile50.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\b\zescope\trench50.asc';... 5,0,683,538,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\c\profile17.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\c\zescope\bowl17.asc';... 5,0,648,533,'S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\d\profile17.png','S:\private\djh2v07\Other stuff\My papers\masters grayscale\figures\figure 3\d\zescope\cone17Pow3_2.asc'}; if ~isempty(cropIms) pathiInds = cell2mat(cropIms(:,1)); jInds = cell2mat(cropIms(:,2)); else pathiInds = []; jInds = []; end rescaleVal = 1.40;%how much bigger need to make ideal im to equal size at sample % for pathi = 7:size(cropIms,1) for pathi = 6:8 path = cropIms{pathi,6}; writePath = cropIms{pathi,5}; endpath = strfind(path,'\'); writeEndPath = strfind(writePath,'\'); currfile = path(endpath(end)+1:end); % folderconts = dir(path); % path = 'S:\private\djh2v07\Other stuff\results\20170731 nickel greyscale zemaps\'; % numfiles = size(folderconts,1); % for j = 1:numfiles % currfile = folderconts(j).name; % if length(currfile)<=3 || ~strcmp(currfile(end-2:end),'asc') % continue; % end % currIm = imread([path,currfile]); currIm = flipud(dlmread([path],' ',[15,0,15+1039,1391])); currIm = currIm - median(currIm(:)); currIm = currIm/1000;%get to µm % currIm = currIm/max(currIm(:)); % imwrite(currIm,[path,'result',num2str(j),'.bmp']); % currImEn = imadjust(currIm); % imwrite(currImEn,[path,'resultEnhanced',num2str(j),'.bmp']); % figure(1); fid = fopen([path]); for ti = 1:7 tline = fgets(fid); if ti==6 xmax = tline; xmax = strrep(xmax,'# x-length = ',''); xmax = str2num(xmax); xmax = xmax/1000;%get to um end if ti==7 ymax = tline; ymax = strrep(ymax,'# y-length = ',''); ymax = str2num(ymax); ymax = ymax/1000;%get to um end end pixX = xmax/size(currIm,2); % if ismember(pathi,pathiInds) && ismember(j,jInds) % cropImsI = find(pathiInds==pathi & jInds==j); cropImsI = pathi; currIm2 = circshift(currIm,[size(currIm,1)/2 - cropIms{cropImsI,4},size(currIm,2)/2 - cropIms{cropImsI,3}]); idealIm = double(imread(cropIms{cropImsI,5})); % xCropMin = cropIms{cropImsI,3}; % xCropMax = cropIms{cropImsI,4}; % yCropMin = cropIms{cropImsI,5}; % yCropMax = cropIms{cropImsI,6}; % else % xCropMin = 1; % xCropMax = size(currIm,2); % yCropMin = 1; % yCropMax = size(currIm,1); % end if cropImsI > 4%saved ideal ims differently for stuff in figure 4 than figure 3 for some reason, quicker to do this hack than track down where fig 4 ims were generated and make consistent idealIm = -idealIm; else idealIm = idealIm - max(idealIm(size(idealIm,1)/2,:)); end idealIm2 = imresize(idealIm,rescaleVal*size(idealIm),'nearest'); idealIm3 = PasteCentre(idealIm2,zeros(size(currIm))); idealIm5 = idealIm3; imVals = unique(idealIm3); for g = -1:1 for h = -1:1 idealIm4 = zeros(size(idealIm3)); currIm3 = circshift(currIm2,[g,h]); if cropIms{cropImsI,2}~=0 rotCurrIm = imrotate(currIm3,cropIms{cropImsI,2},'crop'); else rotCurrIm = currIm3; end % for k = 1:359 % rotCurrIm = rotCurrIm + imrotate(currIm3,k,'bilinear','crop'); % end % rotCurrIm = rotCurrIm/360; for m = 1:length(imVals) idealIm4(idealIm3 == imVals(m)) = mean(rotCurrIm(idealIm3 == imVals(m))); end % aveLineProf = mean(rotCurrIm(floor(size(rotCurrIm,1)/2)-cropIms{cropImsI,1}:floor(size(rotCurrIm,1)/2)+cropIms{cropImsI,1}-1,:)); aveLineProf = idealIm4(floor(size(idealIm4,1)/2),:); % if strcmp(currfile,'bowl17.asc') % idealIm2 = idealIm5/min(idealIm(size(idealIm,1)/2,:))*(-0.560); % else idealIm2 = idealIm5/min(idealIm(size(idealIm,1)/2,:))*min(medfilt1(aveLineProf,10)); % end % plot(1:size(rotCurrIm,2),aveLineProf,linspace(95,size(rotCurrIm,2)-96,size(idealIm,2)),idealIm(size(idealIm,1)/2,:)) % plot((1:size(rotCurrIm,2))*pixX,aveLineProf,linspace(44,size(rotCurrIm,2)-44,size(idealIm2,2))*pixX,idealIm2(size(idealIm2,1)/2,:));%pixel ratio from measuring features is 1.45 asc image to ideal image, ideal image is 900 wide, asc is 1392 wide, thus want idealIm to cover 900*1.45=1305 pixels centrally, 87 pixels difference between this and width of asc, so take about 44 off either side, looks like good fit plot((1:size(rotCurrIm,2))*pixX,aveLineProf,(1:size(rotCurrIm,2))*pixX,idealIm2(size(idealIm2,1)/2,:));%pixel ratio from measuring features is 1.45 asc image to ideal image, ideal image is 900 wide, asc is 1392 wide, thus want idealIm to cover 900*1.45=1305 pixels centrally, 87 pixels difference between this and width of asc, so take about 44 off either side, looks like good fit imagePath = [writePath(1:writeEndPath(end)-1),'\lineProfiles\result',num2str(pathi),'AsIdealProfile',currfile,'OffsetX',num2str(h),'OffsetY',num2str(g),'.png']; legend('Machined','Ideal','Location','northeast') xlabel('x /µm'); xlim([20,70]); ylabel('z /µm'); yLims = ylim; ylim([yLims(1) - (yLims(2)-yLims(1))/10,yLims(2) + (yLims(2)-yLims(1))/10]);%10% space top and bottom make_figure_setSizes(1,18,3,1); saveas(gcf,imagePath); end end % xVals = linspace(1,xmax,size(currIm,2)); % yVals = linspace(1,ymax,size(currIm,1)); % imagesc(xVals(1:xCropMax-xCropMin+1),yVals(1:yCropMax-yCropMin+1),currIm(yCropMin:yCropMax,xCropMin:xCropMax));colorbar; % imagePath = [path,'result',num2str(j),'AsLineProfile',currfile,'.png']; % make_figure_setSizes(1,18,3,1); % pause(0.00001); % frame_h = get(handle(gcf),'JavaFrame'); % set(frame_h,'Maximized',1); % set(frame_h,'PaperPositionMode','auto') % colormap jet; % axis image; % xlabel('x /µm'); % ylabel('y /µm'); % saveas(gcf,imagePath); %plot in 3D % [X,Y] = meshgrid(xVals,yVals); % % for vE = viewEl % for vA = viewAz % % % viewEl = 40; % % viewAz = 55; % figure(1); % surf(X(1:yCropMax-yCropMin+1,1:xCropMax-xCropMin+1),Y(1:yCropMax-yCropMin+1,1:xCropMax-xCropMin+1),currIm(yCropMin:yCropMax,xCropMin:xCropMax),'EdgeColor','none','FaceLighting',lightStyle); % make_figure_setSizes(1,fontSize,lineWidth,aspectRatio); % view(vA,vE); % daspect([1,1,zratio]) % lightangle(-45,30) % colormap hot % xlabel('x /µm'); % ylabel('y /µm'); % zlabel('z /nm'); % % zlim(zLimits); % frame_h = get(handle(gcf),'JavaFrame'); % set(frame_h,'Maximized',1); % imagePath = [path,'variousAngles\result',num2str(j),'AsFig3D',currfile(1:end-4),'ViewEl',num2str(vE),'ViewAz',num2str(vA),'.png']; % saveas(gcf,imagePath); % end % end % end end