Tuesday, November 8, 2011

Using Imagemagick shell command to crop figures

How to crop figure and save as png.
This is useful for cropping similar figures located in a folder.

Copy the code, save as cropfig.sh
and then run the cropfig.sh in your terminal...

#!/bin/bash
width=1800;
height=1680;
x_offset=502;
y_offset=40;
filelist=`ls | grep '.png'`
for image_file in $filelist
do
preextensionfilename=`convert $image_file -format "%t" info:`
convert $image_file -crop ${width}x${height}+${x_offset}+${y_offset} \
${preextensionfilename}_${width}x${height}.png
done


Thursday, November 3, 2011

Remove the .DS_Store from the file list

Sometimes, working on the filelist is troublesome because of the .DS_Store

WhereAqua = pwd;

files = dir(WhereAqua);

% Remove the '.DS_Store' from the list
if strcmp(files(3).name, '.DS_Store')
files(3) = []
end


There is another way too!
fileLIST = dir;
N = length(fileLIST); % fileLIST.name
 status = mkdir(pwd, 'hdfClass'); 

if exist('.DS_Store','file')
! rm .DS_Store
fn =  fileLIST(4).name;
else
fn =  fileLIST(3).name;  

-->

Monday, September 12, 2011

To replace the un-necessary strings in filename

Somehow, the filenames had infections with the extra '%E7%E7htm'.
What surprises me is that not all files had the same error.
So, I wrote a simple code to get rid of the extra characters in the filename/ extension.



% To replace   '%E7%E7htm' by 'htm'

% fn = '2Oct_09.%E7%E7htm'
list = dir;

jj = 1;
while jj < length ( list)
    fn = list(jj,1).name;
    [pathstr, name, ext] = fileparts(fn)
    if  strcmp(ext,'.%E7%E7htm') % ~list(jj,1).isdir
        
%         if strcmp(fn(9:15),'%E7%E7h')
          newfn=  strrep(fn, '%E7%E7h', 'h');
%         end
          system([ 'mv ' fn,' ' newfn])
        
%       disp('asdf')  
    end
    jj = jj+1;
end


Wednesday, September 7, 2011

Add Waving Nepali Flag widget in blogger







This post is about how to add a widget to blogspot blogs.


The code is:
<form method="POST" action="http://www.blogger.com/add-widget">
<input type="hidden" name="widget.title" value="NP Flag"/>
<input type="hidden" name="widget.content" value="<a style='display:scroll; position:fixed; bottom:100px; left:24px;' href='#'><img src='http://i1202.photobucket.com/albums/bb377/nabinkm/nepalflag.gif' alt='np flag' width='75' height='100' border='0' /></a>"/>
<input type="hidden" name="widget.template" value="<data:content/>" />
<input type="hidden" name="infoUrl" value="http://www.nabinkm.com"/>
<input type="hidden" name="logoUrl" value="#"/>
<input type="submit" name="go" value="Add NP flag"/>
</form>


Sunday, September 4, 2011

Twitter Follow badge for blogger with Nepal.gif Flag

Cool GIF flag in blogspot blog with twitter follow button

Add the following code in the html code of your blog before </body> tag

<!-- twitter follow badge by go2web20 -->
<script src='http://www.go2web20.net/twitterfollowbadge/1.0/badge.js' type='text/javascript'/>
<script charset='utf-8' type='text/javascript'><!--
tfb.account = 'nabinkm';
tfb.label = 'follow-me';
tfb.color = '#2f3192';
tfb.side = 'r';
tfb.top = 136;
tfb.showbadge();
--></script>
<!-- end of twitter follow badge -->



Now insert the html at any place in the body. For blogger blogs, I find it easy to add html element and add it there.



<a style="display:scroll;position:fixed;bottom:100px;left:1px;" href="http://www.twitter.com/nabinkm" target="_blank"><img height="97" style="border:0;" src="http://i.imgur.com/t2Iha.jpg" /></a>
<a href="http://www.twitter.com/nabinkm"> @nabinkm </a>



<a style="display:scroll;position:fixed;bottom:100px;left:24px;" href="http://www.twitter.com/nabinkm" target="_blank"><img style="border:0;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWmpT3pwoLheK3o6ROc-nhiIZiiSkTnrSW0RRRM8xhY6H35AIjpcNmVsAOkAl1ayZ-i0ontoTjfmI6EyJIz8P0SQY_nCi-gY0zahpWg32ApxzSlHKQig8lBYIStO2MT0O4PDfiD2hX4ldH/s155/nepalflag.gif" height="100" width="75" /></a>


Wednesday, August 31, 2011

Hex code for Colormap, matlab

I wanted to set the color code for the table to match with that of the figure.

colormap(jet(33))
labels = {'0','1','2','3'};
lcolorbar(labels,'fontweight','bold')
map2 = colormap; map2( 1, : ) = 1; colormap(map2)
cmap = colormap; % cmap nicely puts colormap into 3 col data

perCmap= (single(round(cmap.*255))); % convert to 255 scale
% You can use one of these options:
colorcell = ['rgb(' num2str(perCmap(1,1)), ',', num2str(perCmap(1,2)), ',', num2str(perCmap(1,3)) ')']

colorcell = ['#' (dec2hex(perCmap(1,1))), dec2hex(perCmap(1,2)), dec2hex(perCmap(1,3)) ]
% the second worked best for me

% I then set it to fid1 for txt file, which I was writing.
<td style="color:#ffffff" bgcolor="%s">
% where %s was the string set as colorcell for open fid fprintf(fid1,'<h1>%s <td/h1>', htmlH1);