//mylib命名空间定义
namespace mylib
{
extern "C"
{
#include "mylib/mylib.h"
#include "mylib/array.h"
#include "mylib/image.h"
#include "mylib/histogram.h"
}
};
以下主要说明使用array.h,image.h的方式
array的结构
typedef struct
{ Array_Kind kind; // Interpreation of the array: one of the four enum constants above
Value_Type type; // Type of values, one of the eight enum constants above
int scale; // # of bits in integer values
int ndims; // Number of dimensions of the array
Size_Type size; // Total number of elements in the array (= PROD_i dims[i])
Dimn_Type *dims; // dims[i] = length of dimension i
int tlen; // Length of the text string text
string text; // An arbitrary string label
void *data; // A block of size sizeof(type) * size bytes holding the array.
} Array;
Array_Kind : { PLAIN_KIND, RGB_KIND, RGBA_KIND, COMPLEX_KIND }
If an RGB_KIND array, then the outermost dimension is 3 and (A[0,α],A[1,α],A[2,α]) is an rgb color triple for each index sequence α. If an RGBA_KIND array, then the outermost dimension is 4 and (A[0,α],A[1,α],A[2,α],A[3,α]) is an rgba color for each α.
Value_Type : { UINT8_TYPE, UINT16_TYPE, UINT32_TYPE, UINT64_TYPE,
INT8_TYPE, INT16_TYPE, INT32_TYPE, INT64_TYPE,
FLOAT32_TYPE, FLOAT64_TYPE }
读取image流程
读取tif某时间点,保存到array中间去。
string imgFilename(basename + ".tif");
mylib::Array* img = mylib::Read_Image((char*)(imgFilename.c_str()),0);
上面的函数说明:
Array *G(Read_Image)(string file_name, int layer)
{ return (read_array(image_reader,”Read_Image”,file_name,layer,NULL)); }
写入image流程
boolean Write_Image(string file_name, Array *image, Image_Compress compress)
{ Layer_Bundle WList;
Array *AList[1];
Image_Target Target;
WList.num_layers = 1;
WList.layers = AList;
AList[0] = image;
Target.file = file_name;
return (write_tiff("Write_Image",&Target,image_writer,&WList,NULL,compress));
}
写入流程:
//1、定义写入图像名称
string imgRawFilename(imgBasename + "RawBckgSubt_" + itoa + ".tif" );
//2、构造array的纬度和大小
const static int dimsImage = 3;//to be able to precompile code
mylib::Dimn_Type dims[dimsImage];
for(int ii = 0; ii<dimsImage; ii++)
dims[ii] =dims[ii] = supervoxel::dataDims[ii];
//3、构造RGB_KIND的array
mylib::Array* canvas=Make_Array(mylib::RGB_KIND, mylib::UINT8_TYPE, dimsImage, dims);
//4、构造array数据
***(1)PLAIN_KIND的数据***
mylib::Array* imgL=mylib::Make_Array(mylib::PLAIN_KIND, mylib::UINT16_TYPE,dimsImage, dims);//声明array
mylib::uint16* imgLptr = (mylib::uint16*)(imgL->data);//指向array的data
memset(imgLptr,0,sizeof(mylib::uint16) * (imgL->size));//set all to background
mylib::uint16 auxL = 1;//初始亮度值,设置1;每个supervoxel的亮度一样,不一样的相邻的supervoxel的亮度设置为相差1
for(list<supervoxel>::const_iterator iterS = supervoxelsList[TM].begin(); iterS != supervoxelsList[TM].end(); ++iterS)//循环每个supervoxel
{
for(vector<uint64>::const_iterator iter = iterS->PixelIdxList.begin(); iter != iterS->PixelIdxList.end(); ++iter)//循环每个supervoxel内的pixel
{
imgLptr[*iter] = auxL;
}
auxL++;//更新亮度值,这里可以自己设置含义
}
(2)RGB_KIND的数据
mylib::Array* canvas=Make_Array(mylib::RGB_KIND, mylib::UINT8_TYPE, dimsImage, imgCropped->dims);
mylib::uint8* canvasPtr=(mylib::uint8*)(canvas->data);
double rangeLH=(double)(thrH-thrL);
//循环写入RGB三个分量的数据
for(int cc=0;cc<3;cc++)//the same for loop per color {
//根据图片的原本数据来判断,imgCropped->data保存的是图像本身的数据(也可以像(1)中一样,在遍历piexllist中操作)
mylib::uint16* imPtr=(mylib::uint16*)(imgCropped->data);
for(mylib::Size_Type ii=0;ii<imgCropped->size;ii++){
if(*imPtr<=thrL) *canvasPtr=0;
else if(*imPtr>=thrH) *canvasPtr=255;
else{
//在除去过低亮度和过高亮度的值之间的数据,这样导致RGB每个分量的值是一样的。我们可以在外围构建一个图谱。或者直接在赋值语句上增加外围的变量
*canvasPtr=(mylib::uint8)floor((255.0*(((double)((*imPtr)-thrL))/rangeLH)));
}
canvasPtr++;
imPtr++;
}
}
//5、传入参数,绘制图像
mylib::Write_Image ((char*)(imgRawFilename.c_str()), canvas, mylib::DONT_PRESS)
总体介绍
//读取一个时间点的图片
Array * Read_ImageG (string file_name, int layer)
//读取一个tif内所有图片
Layer_Bundle * Read_Images (string file_name, Layer_Bundle *images RM)
//保存一个时间点的图片
boolean Write_Image (string file_name, Array *array, Image_Compress comp)
//保存多个时间点的图片
boolean Write_Images (string file_name, Layer_Bundle *images, Image_Compress comp)