## Archive for November, 2013

### 8:30 is the perfect time for anything

Tuesday, November 26th, 2013### Correlation does not imply causation

Tuesday, November 26th, 2013### MATLAB gotcha: operator precedence with backslash

Tuesday, November 19th, 2013Matlab’s backslash operator `\`

seemingly acts as a matrix inverse then multiply operator. So I often read:

```
x = A\b
```

as *x = A ^{-1} b*. Indeed,

```
help \
```

reveals in matlab’s documentation:

A\B is the matrix division of A into B, which is roughly the same as INV(A)*B, except it is computed in a different way.

This is very misleading when you consider:

```
x = 2*A\b;
```

If `A=1;b=1;`

then this sets `x`

to `0.5`

! This is because `\`

as a *division* operator does not take precedence over `*`

, and because it comes later in the expression this is equivalent to:

```
x = (2*A)\b;
```

which—so long as A is invertible— is equivalent to:

```
x = 0.5*(A\b);
```

but decidedly not equivalent to:

```
x = 2*inv(A)*b;
```

or

```
x = 2*A^-1*b;
```

which both set `x`

to `2`

.

### Well, it’s probably not February.

Thursday, November 7th, 2013### What color are tennis balls?

Friday, November 1st, 2013Some colleagues and I were debating this today. Of my enormous dataset so far of 6 people, 3 vote for yellow and 3 for green. Interesting the yellow votes all came from Europeans and the greens from non-Europeans. Here’s a very rushed experiment to determine the average color of a tennis ball. From top to bottom: I took a screen capture of a google search for `tennis ball`

, created a mask that mostly contains just the tennis balls, then took an average of the masked colors resulting in the solid bottom color.

If you ask me—and I think you should—I’ll tell you that’s green.

Here’s the matlab script I used to create this:

```
im = imresize(im2double(imread('tennis-ball-google-search.png')),1.0);
ntsc = rgb2ntsc(im);
M = [ntsc(:,:,1)>0.5 & ntsc(:,:,2)>0];
avg = sum(sum(bsxfun(@times,M,im),1),2)./sum(M(:));
comp = [...
im; ...
repmat(M,[1 1 3]); ...
bsxfun(@times,M,im); ...
repmat(avg,[size(im,1) size(im,2) 1])];
imshow(comp);
```

### Convert mkv into high quality mp4 for iPad

Friday, November 1st, 2013Here’s what I’m using to convert 1080p BluRay rips from `.mkv`

to `.mp4`

s for playing back on the iPad.

```
ffmpeg -i input.mkv -acodec aac -ac 2 -strict experimental -ab 160k -s 1920x1080 -vcodec copy -f mp4 -threads 0 output.mp4
```

**Update:** This only works if the input .mkv file is already using h264 as the video codec (see, it’s copying the video rather than transcoding it). Otherwise, you’ll need this (takes much longer):

```
ffmpeg -i input.mkv -acodec aac -ac 2 -strict experimental -ab 160k -vcodec libx264 -preset slow -profile:v baseline -level 30 -maxrate 10000000 -bufsize 10000000 -b 1200k -f mp4 -threads 0 output.mp4
```