by henk21cm » Wed Feb 27, 2008 3:08 pm
Doug, a simple script in Matlab, in order to add a scale bar to an image.
- 1) Save the apod picture with your browser on your local disk
2) Start Matlab
3) Run the script
4) Answer the questions
It will display the image with a scale bar.
The code is below. It isn't rocket science, neither very elegant, it works for me. It might work for you, no claims please.
Code: Select all
function apod
% Read your image to be provided with a scale
[filename, filepath] = uigetfile('*.jpg', 'Get your APOD picture');
image_read = imread([filepath filename]);
% Prompt the user for the scale
prompts = {'Length scale as in kPc, AU or km', ...
'Number of pixels for the same length scale'};
result = inputdlg(prompts, 'Provide a scale', 1, {'100 km', '90'});
% Some error handling
if isempty(result)
msgbox('No data, no scalefactor');
return;
end
% Convert to double
scalefactor = floor(str2double(result{2}));
% Size of the image
s = size(image_read);
% Determine the right lower corner
lrs = s(2)- 19 - scalefactor;
lre = s(2)- 20;
lv = s(1) - 40;
% Add a scale bar in white
image_read(lv:lv+2, lrs:lre, 1) = uint8(ones(3,scalefactor)*255);
image_read(lv:lv+2, lrs:lre, 2) = uint8(ones(3,scalefactor)*255);
image_read(lv:lv+2, lrs:lre, 3) = uint8(ones(3,scalefactor)*255);
% Add a scale bar in black
lv = lv+3;
image_read(lv:lv+2, lrs:lre, 1) = uint8(zeros(3,scalefactor));
image_read(lv:lv+2, lrs:lre, 2) = uint8(zeros(3,scalefactor));
image_read(lv:lv+2, lrs:lre, 3) = uint8(zeros(3,scalefactor));
% Open a figure and display the apod
figure(1);
image(image_read);
% Add the length scale
t = text(lrs, lv-20, result{1});
set(t, 'color', [1 1 1]); % White
t = text(lrs, lv+20, result{1});
set(t, 'color', [0 0 0]); % Black
% Remove non relevant info, display a circle as a circle
set(gca, 'visible', 'off', 'dataaspectratio', [1 1 1]);
return;
I tested the script with an apod of mimas, both normal as negative.
Doug, a simple script in Matlab, in order to add a scale bar to an image.
[list]1) Save the apod picture with your browser on your local disk
2) Start Matlab
3) Run the script
4) Answer the questions
[/list]
It will display the image with a scale bar.
The code is below. It isn't rocket science, neither very elegant, it works for me. It might work for you, no claims please.
[code]function apod
% Read your image to be provided with a scale
[filename, filepath] = uigetfile('*.jpg', 'Get your APOD picture');
image_read = imread([filepath filename]);
% Prompt the user for the scale
prompts = {'Length scale as in kPc, AU or km', ...
'Number of pixels for the same length scale'};
result = inputdlg(prompts, 'Provide a scale', 1, {'100 km', '90'});
% Some error handling
if isempty(result)
msgbox('No data, no scalefactor');
return;
end
% Convert to double
scalefactor = floor(str2double(result{2}));
% Size of the image
s = size(image_read);
% Determine the right lower corner
lrs = s(2)- 19 - scalefactor;
lre = s(2)- 20;
lv = s(1) - 40;
% Add a scale bar in white
image_read(lv:lv+2, lrs:lre, 1) = uint8(ones(3,scalefactor)*255);
image_read(lv:lv+2, lrs:lre, 2) = uint8(ones(3,scalefactor)*255);
image_read(lv:lv+2, lrs:lre, 3) = uint8(ones(3,scalefactor)*255);
% Add a scale bar in black
lv = lv+3;
image_read(lv:lv+2, lrs:lre, 1) = uint8(zeros(3,scalefactor));
image_read(lv:lv+2, lrs:lre, 2) = uint8(zeros(3,scalefactor));
image_read(lv:lv+2, lrs:lre, 3) = uint8(zeros(3,scalefactor));
% Open a figure and display the apod
figure(1);
image(image_read);
% Add the length scale
t = text(lrs, lv-20, result{1});
set(t, 'color', [1 1 1]); % White
t = text(lrs, lv+20, result{1});
set(t, 'color', [0 0 0]); % Black
% Remove non relevant info, display a circle as a circle
set(gca, 'visible', 'off', 'dataaspectratio', [1 1 1]);
return;
[/code]
I tested the script with an apod of mimas, both normal as negative.