/*
Translated from ImageJ Java Pluging into MATLAB MEX c code by
Tom Macura <tmacura@nih.gov>
July 21st, 2006
Modded by Chris Coletta and Ilya Goldberg to deal with 16-bit/chanel RGB,
and make it independent of MATLAB
*/
/* G.Landini at bham ac uk
30/Mar/2004 released
03/Apr/2004 resolved ROI exiting
07/Apr/2004 added Methyl Green DAB vectors
08/Jul/2004 shortened the code
01/Aug/2005 added fast red/blue/DAB vectors
02/Nov/2005 changed code to work with image stacks (DLC - dchao at fhcrc org)
02/Nov/2005 changed field names so user-defined colours can be set within
macros (DLC - dchao at fhcrc org)
This plugin implements stain separation using the colour deconvolution
method described in:
Ruifrok AC, Johnston DA. Quantification of histological
staining by color deconvolution. Analytical & Quantitative
Cytology & Histology 2001; 23: 291-299.
The code is based on "Color separation-30", a macro for NIH Image kindly provided
by A.C. Ruifrok. Thanks Arnout!
The plugin assumes images generated by color subtraction (i.e. light-absorbing dyes
such as those used in bright field histology or ink on printed paper) but the dyes
should not be neutral grey.
I strongly suggest to read the paper reference above to understand how to determine
new vectors and how the whole procedure works.
The plugin works correctly when the background is neutral (white to light grey),
so background subtraction and colour correction must be applied to the images before
processing.
The plugin provides a number of "bulit in" stain vectors some of which were determined
experimentally in our lab (marked GL), but you may have to determine your own vectors to
provide a more accurate stain separation, depending on the stains and methods you use.
Ideally, vector determination should be done on slides stained with only one colour
at a time (using the "From ROI" interactive option).
The plugin takes an RGB image and returns three 8-bit images. If the specimen is
stained with a 2 colour scheme (such as H & E) the 3rd image represents the
complimentary of the first two colours (i.e. green).
Please be *very* careful about how to interpret the results of colour deconvolution
when analysing histological images.
Most staining methods are not stochiometric and so intensity of the chromogen
may not correlate well with the quantity of the reactants.
This means that intensity of the colour may not be a good indicator of
the amount of material stained.
Read the paper!
*/
#include <errno.h>
#include <math.h>
#include <float.h> // for DBL_MAX
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <tiffio.h>
#include "readTIFF.h"
#define XSTR(s) STR(s)
#define STR(s) #s
#define DEF_ITER 5
typedef struct {
char *argP; // a non-specified stain has this NULL
char label[256];
char isRGB;
double MODx,MODy,MODz;
double max,min;
} stain_t;
void usage (const char *argv0, const char *message);
void prepare_conversion_vectors(char **stain, double *q);
void getStainVecs (stain_t *stains, int nstains);
void getNormStainMODs (stain_t *stains, double *RGBwht, double *cosx, double *cosy, double *cosz);
void getStainMat(stain_t *stains, double *RGBwht, double *q);
double color_decon (float *inBuf,float *outBuf,size_t imagesize,double max_pix_val,double *RGBwht,stain_t *stains);
void getStainMODs (stain_t *stains,int nstains,double *MODx,double *MODy,double *MODz);
void setStainMODs (stain_t *stains,int nstains,double *MODx,double *MODy,double *MODz);
void getNewMOD (float *inBuf,float *outBuf,size_t imagesize,double *RGBwht,stain_t *stains, int nstains, double *MODx1,double *MODy1,double *MODz1);
char pure_integer (const char *p, long *num);
int main (int argc, char **argv)
{
int arg,ret, filename_arg;
TIFF* tif;
float *inBuf,*outBuf;
void *img_stain;
uint16_t bits;
uint32_t width,height;
char outfile[256],basename[256],ext[256],error[256],*cp;
int nstains=0, stain_idx;
stain_t stains[3];
size_t i,j;
size_t imagesize;
uint8_t *img_stain8;
uint16_t *img_stain16;
uint32_t *img_stain32;
int minbits; // The minimum number of bits to express the maximum RGB value in the TIFF
// Calculated by ReadRGBTIFFDataFlt
char whtLvl=0;
double MODx1[3],MODy1[3],MODz1[3];
double max_pix_val; // maximum possible value for scaling (2^bits type of number)
double RGBwht[3];
double Rin,Gin,Bin;
int iter_idx, n_iter = 1, best_iter;
long iter_in;
double total_stain; // the total stain accounted for in each iteration
double bestMODx[3],bestMODy[3],bestMODz[3];
double best_total_stain; // the best total stain accounted for in each iteration
if (argc < 3) {
usage (argv[0],"Insufficient arguments");
}
/*
String [] stain={"From ROI", "H&E", "H DAB","FastRed FastBlue DAB","Methyl Green DAB",
"H&E DAB", "H AEC","Azan-Mallory","Alcian blue & H","H PAS","RGB","CMY",
"User values"};
IGG: stain is specified per-channel, so -s0 H -s1 E will put the default Haem matrix
in MOD*[0], and the Eosin matrix in MOD*[1]. Viable stain strings are: "H", "E",
"DAB", "FastRed", "FastBlue", "MethylGreen", "AEC", "Azan-Mallory", "AlcianBlue",
"PAS", "R", "G", "B", "C", "M", "Y" To use specific user values, use
-s0 '123.3 456.7 234.3', -s1 '1.23 4.56 7.89' corresponding to the RGB values.
The parameter following s0, s1 or s2 is checked against all the stain strings,
and finally we try to sscanf 3 floats. If we don't get 3 floats, then the
parameter is malformed.
*/
memset (stains, 0, sizeof (stains));
// Get the CLI params
for (arg = 1; arg < argc-1; arg++) {
// Stain specification (will be parsed/checked later)
if ( !strcmp (argv[arg],"-s") || !strcmp (argv[arg],"-sOD")) {
filename_arg = arg + 2; // -s requires a following arg
nstains++;
if (nstains < 4) {
stains[nstains-1].argP = argv[arg+1];
// Determine if an RGB triplet is an OD representation of stains
if ( sscanf (argv[arg+1],"%lf,%lf,%lf",&Rin,&Gin,&Bin) == 3 && !strcmp (argv[arg],"-s"))
stains[nstains-1].isRGB = 1;
else
stains[nstains-1].isRGB = 0;
} else {
usage (argv[0],"A maximum of 3 stains are supported");
}
// Get the white-level
} else if ( !strcmp (argv[arg],"-w") ) {
filename_arg = arg + 2; // -w requires a following arg
if ( sscanf (argv[arg+1],"%lf,%lf,%lf",&Rin,&Gin,&Bin) != 3 ) {
usage (argv[0],"-w parameter is malformed. Three white levels expected (R,G,B)");
} else {
whtLvl = 1;
RGBwht[0] = Rin;
RGBwht[1] = Gin;
RGBwht[2] = Bin;
fprintf (stdout,"white-level = (%lf, %lf, %lf)\n",RGBwht[0],RGBwht[1],RGBwht[2]);
}
} else if ( !strcmp (argv[arg],"-i") ) {
filename_arg = arg + 1;
if ( pure_integer (argv[arg+1],&iter_in) ) {
filename_arg++; // -i has an optional following arg
if (iter_in > 0) {
n_iter = iter_in;
} else {
usage (argv[0],"-i parameter is malformed. Must greater than 0");
}
} else {
n_iter = DEF_ITER;
}
}
}
if (nstains < 1) usage (argv[0],"A minimum of 1 stain must be specified");
if (filename_arg >= argc) usage (argv[0],"At least one tiff file must be specified");
// suppress warnings
TIFFSetWarningHandler (NULL);
for (arg = filename_arg; arg < argc; arg++)
{
fprintf (stdout,"File: %s\n",argv[arg]);
tif = TIFFOpen(argv[arg],"r");
if (!tif) {
fprintf (stderr,"Could not open %s: %s\n",argv[arg], strerror (errno));
exit (-1);
}
// Check if its proper RGB
if ( (ret = isRGB (tif)) < 0) {
GetReadTIFFError (ret,error);
fprintf
没有合适的资源?快使用搜索试试~ 我知道了~
wndchrm-1.50rc0.tar.gz_classification c_visual c
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 12 浏览量
2022-09-20
21:05:59
上传
评论
收藏 796KB GZ 举报
温馨提示
共385个文件
h:269个
txt:34个
cpp:34个
op is classification
资源推荐
资源详情
资源评论
收起资源包目录
wndchrm-1.50rc0.tar.gz_classification c_visual c (385个子文件)
configure.ac 9KB
sources.am 11KB
Makefile.am 3KB
Array 304B
AUTHORS 701B
color_deconvolution.c 30KB
readTiffData.c 17KB
ChangeLog 0B
Cholesky 775B
CholmodSupport 2KB
configure 185KB
COPYING 18KB
Core 12KB
TrainingSet.cpp 164KB
cmatrix.cpp 57KB
specfunc.cpp 56KB
wndchrm.cpp 52KB
Wavelet.cpp 35KB
FuzzyCalc.cpp 35KB
CVIPtexture.cpp 27KB
convolution.cpp 19KB
Tasks.cpp 19KB
FeatureAlgorithms.cpp 19KB
FeatureNames.cpp 18KB
signatures.cpp 15KB
zernike.cpp 11KB
WORMfile.cpp 10KB
FeatureStatistics.cpp 9KB
CombFirst4Moments.cpp 8KB
tamura.cpp 8KB
gabor.cpp 7KB
ImageTransforms.cpp 6KB
ChebyshevFourier.cpp 6KB
chebyshev.cpp 5KB
DataGrid2D.cpp 5KB
haralick.cpp 5KB
wt.cpp 4KB
wndchrm_error.cpp 4KB
radon.cpp 4KB
DataGrid3D.cpp 3KB
Symlet5.cpp 2KB
WaveletLow.cpp 2KB
WaveletMedium.cpp 1KB
WaveletHigh.cpp 1KB
Filter.cpp 985B
FilterSet.cpp 660B
Common.cpp 116B
Dense 122B
depcomp 23KB
Eigen 37B
Eigen2Support 3KB
Eigenvalues 1KB
Geometry 2KB
OldFeatureNamesFileStr.h 505KB
Transform.h 54KB
GeneralBlockPanelKernel.h 44KB
SparseMatrix.h 39KB
Memory.h 36KB
Functors.h 36KB
JacobiSVD.h 35KB
PlainObjectBase.h 33KB
blas.h 33KB
SuperLUSupport.h 32KB
SimplicialCholesky.h 30KB
TriangularMatrix.h 29KB
SelfAdjointEigenSolver.h 29KB
CwiseNullaryOp.h 29KB
Quaternion.h 28KB
Transform.h 28KB
FullPivLU.h 27KB
DenseCoeffsBase.h 27KB
GeneralProduct.h 26KB
PacketMath.h 25KB
VectorwiseOp.h 24KB
MathFunctions.h 24KB
PaStiXSupport.h 24KB
PermutationMatrix.h 23KB
DenseBase.h 23KB
Assign.h 22KB
FullPivHouseholderQR.h 22KB
MatrixBase.h 22KB
Tridiagonalization.h 22KB
GeneralMatrixVector.h 22KB
PardisoSupport.h 21KB
EigenSolver.h 21KB
LDLT.h 20KB
ColPivHouseholderQR.h 20KB
CholmodSupport.h 19KB
BlockMethods.h 19KB
HouseholderSequence.h 19KB
SparseMatrixBase.h 18KB
PacketMath.h 18KB
SVD.h 18KB
CoeffBasedProduct.h 18KB
PartialPivLU.h 17KB
Complex.h 17KB
RealSchur.h 17KB
Tasks.h 17KB
TriangularMatrixMatrix.h 17KB
Matrix.h 17KB
共 385 条
- 1
- 2
- 3
- 4
资源评论
小波思基
- 粉丝: 74
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功