Archive for the ‘Mathematica’ Category

Retrieve the raw data of Baidu Index Images using Mathematica

Thursday, December 27th, 2012

 

S[{title_, maxX_, maxY_}] := Module[
{importAdress, baiduImage, wantedImage, x, y, dummyCodingList,
codedImage, exportAddress, ps, ps2, ps3},
importAdress = “D:/…/” <> title <> “.jpg”;
baiduImage = Import[importAdress];
wantedImage = ImageTake[baiduImage, {26, 221}, {6, 471}];
x = ImageDimensions[wantedImage][[1]];
y = ImageDimensions[wantedImage][[2]];
dummyCodingList[list_] :=
If[#[[1]] > 0.90 && 0.6 < #[[2]] < 1 && 0 < #[[3]] < 0.7, 1, 0] & /@list;
codedImage = dummyCodingList /@ ImageData[wantedImage];
ps = Sort[Reverse /@ Position[codedImage, 1]];
ps2 = Mean /@ GatherBy

] &] // N;
ps3 = Transpose[{Round[maxX*ps2[[All, 1]]/x],
maxY*(y – ps2[[All, 2]])/y}];
exportAddress = “D:/…/” <> title <> “.csv”;
Export[exportAddress, ps3]
]

S[{“test”, 365, 24000}]