% % This script reads an image, lets you pick some points and then saves % picked data into a file. % % BEWARE: I've uploaded this script just to keep it at hand. It's not % bug-free and you should not trust it. % % The script works nice with GNU Octave v3.6.2 % % Cheers, % Stefano close all clear clc page_screen_output(0); % ############################################################### % ################### Scaling functions ####################### % ############################################################### % ------ Linear scaling function xNew = lin_scale(xIn, xOrig, xXaxis, xOrig_value, xXaxis_value) xScaleFactor = (xXaxis_value - xOrig_value) / (xXaxis - xOrig); % Translating the points xInTransl = xIn - xOrig; % Scaling xInScaled = xInTransl*xScaleFactor; % And then translating again xNew = xInScaled + xOrig_value; endfunction % ------ Log scaling function xNew = log_scale(xIn, xOrig, xXaxis, xOrig_value, xXaxis_value) % Computing logaritms of input values log_xOrig_value = log(xOrig_value); log_xXaxis_value = log(xXaxis_value); xScaleFactor = (log_xXaxis_value - log_xOrig_value) / (xXaxis - xOrig); % Translating the points xInTransl = xIn - xOrig; % Linearly scaling log data xInScaled = xInTransl*xScaleFactor; % Then translating again xInTranslScaled = xInScaled + log_xOrig_value; % And finally converting log-data to actual data xNew = exp(xInTranslScaled); endfunction % ########################################################### % ###################### M A I N ######################## % ########################################################### % Read image imname = input('Name of the image to be read: ', 's'); im = imread(imname); image(im) axis equal % Select axis fprintf('You now have to select three points:\n'); fprintf(' 1) The plot origin (bottom left axis point)\n'); fprintf(' 2) One point on the X axis\n'); fprintf(' 3) One point on the Y axis\n'); fprintf('Also, you will be asked for the corresponding value.\n\n'); fprintf('Pick the origin\n') [xOrig, yOrig] = ginput(1); xOrig_value = input(' X value for the origin: '); yOrig_value = input(' Y value for the origin: '); fprintf('Pick one point on the X axis\n'); [xXaxis, dummy] = ginput(1); xXaxis_value = input('X value for the picked point: '); fprintf('Now Pick one point on Y axis\n'); [dummy, yYaxis] = ginput(1); yYaxis_value = input('Y value for the picked point: '); % Now get points until RETURN is pressed fprintf('Now pick as many points as you like. Press on the image'); fprintf(' when you are done.\n') [xPicked, yPicked] = ginput(); % ------ Elaborating picked points ------ % Is some scaling Logarithmic? % no -> linear linear plot fprintf('\nIs the plot logarithmic?\n'); fprintf('no -> linear linear plot\n'); fprintf('x -> semilogx\n'); fprintf('y -> semilogy\n'); fprintf('xy -> loglog\n'); isLog = input('','s'); switch(isLog) case 'no' xPickedFinal = lin_scale(xPicked, xOrig, xXaxis, xOrig_value, xXaxis_value); yPickedFinal = lin_scale(yPicked, yOrig, yYaxis, yOrig_value, yYaxis_value); fprintf('You have choosed a linear-linear plot. \n'); case 'x' xPickedFinal = log_scale(xPicked, xOrig, xXaxis, xOrig_value, xXaxis_value); yPickedFinal = lin_scale(yPicked, yOrig, yYaxis, yOrig_value, yYaxis_value); fprintf('You have choosed a semilogx-type plot. \n'); case 'y' xPickedFinal = lin_scale(xPicked, xOrig, xXaxis, xOrig_value, xXaxis_value); yPickedFinal = log_scale(yPicked, yOrig, yYaxis, yOrig_value, yYaxis_value); fprintf('You have choosed a semilogy-type plot. \n'); case 'xy' xPickedFinal = log_scale(xPicked, xOrig, xXaxis, xOrig_value, xXaxis_value); yPickedFinal = log_scale(yPicked, yOrig, yYaxis, yOrig_value, yYaxis_value); fprintf('You have choosed a loglog-type plot. \n'); endswitch % Save results? Are you happy with them? fprintf('Save results?\n'); saveMe = input(' Yes: write filename || No: hit ', 's'); if ( numel(saveMe) > 1 ) fID = fopen(saveMe,'w'); fprintf(fID, '%% Free Software is needed for Free Science\n'); fprintf(fID, '%% x | data\n'); for ii = 1:numel(xPicked) fprintf(fID, '%e %e\n', xPickedFinal(ii), yPickedFinal(ii)); end fclose(fID); end