-
Notifications
You must be signed in to change notification settings - Fork 0
/
Macenko et al Walkthrough.m
69 lines (48 loc) · 2.88 KB
/
Macenko et al Walkthrough.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(* ::Package:: *)
(************************************************************************)
(* This file was generated automatically by the Mathematica front end. *)
(* It contains Initialization cells from a Notebook file, which *)
(* typically will have the same name as this file except ending in *)
(* ".nb" instead of ".m". *)
(* *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs. Doing so is equivalent *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end. *)
(* *)
(* DO NOT EDIT THIS FILE. This entire file is regenerated *)
(* automatically each time the parent Notebook file is saved in the *)
(* Mathematica front end. Any changes you make to this file will be *)
(* overwritten. *)
(************************************************************************)
(* ::Input::Initialization:: *)
options[verbose] = True;
options[alpha]=0.01;
options[beta] = 0.15;
(* ::Input::Initialization:: *)
(* Convert the data in an image to a matrix of RGB tuples. This function removes the row/column structure from the image data.
Input: img -- an image file. Assumed to be an RGB image.
Output: an array of RGB tuples with byte data elements.*)
convertToRgbTuples[img_]:= Flatten[ImageData[img, "Byte"], 1];
(* ::Input::Initialization:: *)
(* Convert a short integer (8-bit byte) in the range of 0 to 255 to absorbance. Assumes that a value of 0 represents 0% transmittance and that 255 represents 100% transmittance. Handles special cases of 0% and 100% transmittance for numerical stability. Forces the result to a numerical value (as opposed to symbolic) using default machine precision. *)
convertRgbToOD[trans_]:=Module[
{recip},
recip=trans/255;
Switch[recip, 255, 0.000000001, 0, 3.0, _, N[-Log10[recip]]]
];
(* ::Input::Initialization:: *)
(* Convert an RGB tuple (a list with 3 elements in the range of 0 to 255) to an absorbance tuple.*)
convertRgbTupleToOD[tuple_]:=odTable[[#+1]]&/@tuple;
(* ::Input::Initialization:: *)
(* Convert a list of RGB tuples to absorbance. The input is a list of 3-element lists where each element is a value between 0 and 255.*)convertRgbTupleArrayToOD[tuples_]:=convertRgbTupleToOD /@ tuples;
(* ::Input::Initialization:: *)
tupleAboveThresholdQ[tuple_]:=Module[
{b},
b=options[beta];
Or[tuple[[1]]>b,tuple[[2]]>b, tuple[[3]]>b]
]
(* ::Input::Initialization:: *)
thresholdByBeta[odPixels_]:=Select[odPixels, tupleAboveThresholdQ];
(* ::Input::Initialization:: *)
calcSingularValues[a_]:= N[Sqrt[Sort[Eigenvalues[Transpose[a].a],Greater]]]