for (int i = 0; i < numberOfSpaces; i++) {
System.out.print(" ");
}

这种方法并不简便,尤其多处需要输出的时候。

利用String.format可以简单的实现。

String space = String.format("%" + numberOfSpaces + "s", " ");
System.out.println(space);



posted @ 2012-02-12 12:42 残垣上的舞者 Views(54) Comments(0) Edit

颜色布局描述符 Color Layout Descriptor - CLD是用来描述颜色在图像中空间分布的颜色描述符。MPEG-7标准推荐了很多颜色描述符。包括可伸缩颜色描述符、颜色布局描述符和边缘直方图描述符等用于表示颜色。其中CLD因为可以有效的表示颜色的空间布局,广泛应用于图像检索技术。

这里不对CLD多做介绍(可参看http://en.wikipedia.org/wiki/Color_layout_descriptor)。在网上有很多关于CLD的文献,但是CLD在Matlab中的实现却很少,也很不完整。

以下是刚完成的CLD在Matlab中的实现,因为刚开始用Matlab,可能代码存在不足。

 

function Descriptor = ColorLayout(Image)
Img = Image;

%%颜色分割%%
%%代表色选择%%

[m,n,k] = size(Img);

cnum = 8;
ch = floor(m/cnum); cw = floor(n/cnum);
t1 = (0:(cnum-1))*ch + 1; t2 = (1:cnum)*ch;
t3 = (0:(cnum-1))*cw + 1; t4 = (1:cnum)*cw;

I = zeros([cnum,cnum,3]);
for i = 1 : cnum
for j = 1 : cnum
lstart=(i-1)*ch;
hstart=(j-1)*cw;

temp = Img(t1(i):t2(i), t3(j):t4(j), :);

for p=1:ch
for q=1:cw
temp(p,q,1)=Img(p+lstart,q+hstart,1);
temp(p,q,2)=Img(p+lstart,q+hstart,2);
temp(p,q,3)=Img(p+lstart,q+hstart,3);
end
end

temp1=temp(:,:,1);
temp2=temp(:,:,2);
temp3=temp(:,:,3);

tmp1 = temp1(:)';
tmp2 = temp2(:)';
tmp3 = temp3(:)';

I(i,j,1) = mean(tmp1);
I(i,j,2) = mean(tmp2);
I(i,j,3) = mean(tmp3);
end
end

%%DCT转换%%

I=rgb2ycbcr(I); %转换为YCbCr色彩空间

DCTY = I(:,:,1);
DCTCb = I(:,:,2);
DCTCr = I(:,:,3);

T=dctmtx(8);
DCTcoe1=blkproc(DCTY,[8,8],'P1*x*P2',T,T');
DCTcoe2=blkproc(DCTCb,[8,8],'P1*x*P2',T,T');
DCTcoe3=blkproc(DCTCr,[8,8],'P1*x*P2',T,T');

mask=[1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];

B1=blkproc(DCTcoe1,[8 8],'P1.*x',mask);
B2=blkproc(DCTcoe2,[8 8],'P1.*x',mask);
B3=blkproc(DCTcoe3,[8 8],'P1.*x',mask);

I(:,:,1)=blkproc(B1,[8 8],'P1*x*P2',T',T);
I(:,:,2)=blkproc(B2,[8 8],'P1*x*P2',T',T);
I(:,:,3)=blkproc(B3,[8 8],'P1*x*P2',T',T);

% Set up array for fast conversion from row/column coordinates to
% zig zag order. 下标从零开始,从MPEG的C代码拷贝过来的
zigzag = [ 0, 1, 8, 16, 9, 2, 3, 10, ...
17, 24, 32, 25, 18, 11, 4, 5, ...
12, 19, 26, 33, 40, 48, 41, 34, ...
27, 20, 13, 6, 7, 14, 21, 28, ...
35, 42, 49, 56, 57, 50, 43, 36, ...
29, 22, 15, 23, 30, 37, 44, 51, ...
58, 59, 52, 45, 38, 31, 39, 46, ...
53, 60, 61, 54, 47, 55, 62, 63];

zigzag = zigzag + 1;
% 将输入块变成3x64的向量

D(1,:) = reshape(I(:,:,1)',1,64);
D(2,:) = reshape(I(:,:,2)',1,64);
D(3,:) = reshape(I(:,:,3)',1,64);

Descriptor = D(:,zigzag); % 对I按照查表方式取元素,得到 zig-zag 扫描结果





posted @ 2012-02-02 00:12 残垣上的舞者 Views(897) Comments(0) Edit
[r,c,d] = size(rgbImage);

 

In that line of code:

  • r is the number of rows in the image (i.e. the size of the first dimension).
  • c is the number of columns in the image (i.e. the size of the second dimension).
  • d can be referred to as the "depth" or "planes" of the image (i.e. the size of the third dimension).

For an RGB (or Truecolor) image, d is always 3. The first plane contains the degree of red in each pixel of the image,

the second plane contains the degree of green in each pixel of the image, and the third plane contains the degree of

blue in each pixel of the image.

 

[From]http://stackoverflow.com/questions/2612113/what-are-the-3-dimensions-of-an-rgb-image-in-matlab

posted @ 2012-01-14 16:33 残垣上的舞者 Views(640) Comments(0) Edit
  • 为什么不使用float / double?

使用java时会遇到money类型的选择问题,首先想到的是float / double。如果只是简单的货币计算,很难发现用float会有问题。出现问题的原因是使用float / double(已经相应的包装类Float / Double)会出现舍入误差(rounding errors),不能精确的表示十进制数。例如下面的例子:

 

 1 public class countMoney {
2 public static void main(String[] args) {
3 float m1 = 0.1f;
4 float m2 = 9.0f;
5 System.out.println(mulMoney(m1, m2));
6 }
7
8 private static float mulMoney(float m1, float m2) {
9 return m1 * m2;
10 }
11 }

 

结果输出0.90000004,而不是0.9。十进制数0.1用二进制存储,被表示的值为0.0999999999999999996。所以得到的结果并不是预期的0.9。

  • 怎样表示money?

使用BigDecimal来表示货币。现在来重新实现这个例子:

 

 1 public class countMoney {
2 public static void main(String[] args) {
3 BigDecimal m1 = new BigDecimal("0.1");
4 BigDecimal m2 = new BigDecimal("9.0");
5 System.out.println(mulMoney(m1, m2));
6 }
7
8 private static BigDecimal mulMoney(BigDecimal m1, BigDecimal m2) {
9 return m1.multiply(m2);
10 }
11 }

 

输出0.90。

BigDecimal可表示任意精度的小数,不管它的范围有多大。BigDecimal是用array来存储数字的,每一次输入表示一个数字。因此,BigDecimal可以表示任意大小的数。

另外,BigDecimal是一个类,不是基本类型,需要调用方法来实现数的运算。它有四中方法:add, subtract, multiply, 和 divide。这里m1和m2相乘采用了multiply。

  • 表示money的其他方法?

currency可表示世界货币。

使用int / long表示penny。

  • 参考文献:

Working with money in Java

Presenting money

 

posted @ 2011-12-29 17:34 残垣上的舞者 Views(1461) Comments(13) Edit

      学习Java遇到各种API,快速查询和了解使用技巧成了问题。Java API Search(点击进入下载页面)添加了支持在Chrome

omnibox快速查找和自动完成Java 7 API类的功能。

安装这个插件后,只要在Chrome搜索栏中输入java加空格,就会出现Java API Search标志,如下图。

然后输入你要查询的函数名即可。

 

关于Ominibox:

可以把个人常用搜寻项搜集起来,例如,输入Halo,就可查询单词(中英文都可以)。

posted @ 2011-12-24 17:38 残垣上的舞者 Views(422) Comments(0) Edit
Google不仅是搜索引擎,它有很多实用的工具,包括我们经常使用的Gmail,Translate。miniawayday被推荐了很多google很多新的实用工具,遗憾的是有些国内不能应用,所以不被大家熟知。还好有很多的替代产品。GTalk——即时通讯 Google Talk是一款免费的即时通讯工具。它支持即时聊天和语音留言。Gmail集成了Gtalk,即talk功能,可以与其他拥有Gmail或者Gtalk工具的用户方便的聊天。这些聊天记录被自动的保存在Gmail账号的chats区域。 目前流行的G+和Gtalk也相互集成。Calendar——日程管理 不管是管理自己的日常事务...Read More
posted @ 2011-12-23 10:30 残垣上的舞者 Views(14) Comments(0)  Edit
Dropbox是一个提供同步本地文件的网络存储在线应用。支持在多台电脑多种操作中自动同步。并可当作大容量的网络硬盘使用。目前很多这种文件存储在线应用采用了小容量免费适用+大容量付费专享的模式。 如果只是小文件分享,Dropbox确实很给力。同步的速度似乎还差强人意。同时,上手很容易,难能可贵。 只是,网站访问需要外链,这点很不给力了。再有就是,大文件因为上传速度慢,最终还是会被放弃,还是会有局限性。Download:http://opendata.baidu.com/software/s?rn=10&wd=dropbox+%CF%C2%D4%D8Read More
posted @ 2011-12-19 22:56 残垣上的舞者 Views(13) Comments(0)  Edit
今天miniawayday和几个同学闲谈到github访问的问题,今天自己也被问的解释不清了。追根还是只进行了操作,究竟为什么这么操作?每个操作到底帮助你解决了哪些工作?这些还是没弄清楚。回来重新试了一下,希望遇到和我们同样问题的“Gitter”可以解惑。如果有不对的,也希望回复讨论。Q1. fetch和pull的区别? 简单来说,git pull = git fetch + git merge 可以用git fetch来随时获取你remote分支的更新,但它不会改变你当前的分支。这个操作可以避免当orig...Read More
posted @ 2011-12-18 00:51 残垣上的舞者 Views(96) Comments(0)  Edit
原来可以玩的这么high! 完全喜欢上这个集体。他们是偏执狂,却偏执的很可爱;他们是程序员,却一点也不boring!努力成为其中一员。。。Read More
posted @ 2011-12-17 23:49 残垣上的舞者 Views(26) Comments(0) Edit
从刚开始对Git一无所知,到现在对Git一知半解,觉着应该把学习Git的过程记录下来。 都知道Git是版本控制工具,当然它是分布式的VCS。一提到Git,结伴而来的肯定是和Subversion的比较。自己没用过Subversion,没有发言权,这里有一篇胡桑推荐的为什么要放弃SVN的文章,分享一下(http://www.infoq.com/cn/articles/thoughtworks-practice-partiv)。当然并不说SVN不好,它有支持它的大片“码农粉”,之前就有同学指出“公司一般用SVN,没有不停合并分支的需求,又便于代码集中”。这里只说Git。1. Windows...Read More
posted @ 2011-12-16 15:25 残垣上的舞者 Views(57) Comments(0)  Edit