Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Created August 28, 2014 20:27
Show Gist options
  • Select an option

  • Save tonyfast/cc855d48f5a9b7e8e745 to your computer and use it in GitHub Desktop.

Select an option

Save tonyfast/cc855d48f5a9b7e8e745 to your computer and use it in GitHub Desktop.
A Matlab code to hack Flickr for sharing uniformly gridded, non-image data.
%% Flickr Translation Function
% This code requires:
% JSON Lab: http://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab--a-toolbox-to-encode-decode-json-files-in-matlab-octave
%% Load Example Image
% This example image was provided Dr. Mark Stoudt at NIST. It is surface
% roughness data for High Purity Aluminum. The experiment's detector
% measures the height of aberations on the surface of rolled sheet
% aluminum. The data has postive and negative float values. In the title
% of the Flickr image I have added arguments for scaling and translating
% the data.
%%
% Use OEmbed to get information about the image. OEmbed returns a json
% string that is then de-serialized using JSON Lab.
photourl = 'https://www.flickr.com/photos/tonyfast/13267132114';
oembed_arg = 'https://www.flickr.com/services/oembed/?format=json&url=';
% OEmbed json request. The JSON is serialized as a string.
jsonreq = urlread(horzcat(oembed_arg,photourl));
% De-serialize jsonreq to a matlab structure
image_info = loadjson( jsonreq );
%% Image Info
% OEmbed returns the following information:
% type, title, author_name, author_url, width, height, urlweb_page
% thumbnail_url, thumbnail_width, thumbnail_height, web_page_short_url
% license, license_id, version, cache_age, provider_name, provider_url
%% Scaling the Image Title
% Parse the image title to get the scaling factor and the translation.
% Example: image_info.title: 'Strain220F&scale=4.266667&shift=128.0'
[~,str] = strtok(image_info.title,'&'); % I wish I understood regular expressions :(
transform = struct();
for ii = 1 : 2
[field,str] = strtok(str,'=');
[value,str] = strtok(str,'&');
transform = setfield( transform, ...
field( 2:end ), ...
str2num( value( 2:end)) ...
);
end
%% Re-mapped Image
% Remap the image using the transform variable.
OldImage = imread( image_info.url );
NewImage = (double(OldImage)- transform.shift) / transform.scale;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment