18 #include "l/l_sys_def.h"
26 #define MAX_CHARS 2000
32 #define MACH_MOTOROLA 1
50 #define MATRIX_SPARSE 2
53 #warning "[Code police] Do not put 'using namespace' in global scope of header."
54 using namespace kjb_c;
68 T* pBuffer,
int& Width,
int& Height);
72 const int Height,
const char* strMatName,
73 const char* strFilename);
77 bool ReadMatfile(CImg<T>* pInImg,
const char* strFilename);
83 const char* strMatname,
84 const char* strFilename);
87 bool WriteMatfile(CImg<T>& InImg,
const char* strMatname);
91 bool ReadMatfiles(CImgVec<T>& InVec,
const char *strPrefix);
95 bool WriteMatfiles(
const vector<CImg<T>*>& InVec,
const char *strPrefix);
135 T* pBuffer,
int& Width,
int& Height)
138 if ((pF = fopen(strFilename,
"rb")) == NULL) {
143 if (fread(&matfile, 1,
sizeof(
MATFILE), pF) !=
144 (
unsigned int)
sizeof(
MATFILE)) {
150 if (fread(name,
sizeof(
char), matfile.
namlen, pF) !=
151 (
unsigned int)matfile.
namlen) {
156 const int W = matfile.
ncols;
157 const int H = matfile.
mrows;
159 if (pBuffer == NULL) {
162 pBuffer =
new T[Width*Height];
165 const int EltSize =
sizeof(T);
166 for (
int x = 0;
x <
W;
x++)
167 for (
int y = 0; y < H; y++) {
169 if (fread(&Val, 1, EltSize, pF) != (
unsigned int)EltSize)
171 *(pBuffer+y*W+
x) = Val;
181 const int Height,
const char* strMatName,
182 const char* strFilename)
187 matfile.
type = atoi(strType);
188 matfile.
ncols = Width;
189 matfile.
mrows = Height;
191 matfile.
namlen = strlen(strMatName)+1 ;
194 if ((pF = fopen(strFilename,
"wb")) == NULL)
197 if(fwrite(&matfile, 1,
sizeof(
MATFILE), pF) !=
198 (
unsigned int)
sizeof(
MATFILE)) {
202 if (fwrite(strMatName, 1, (
int)matfile.
namlen, pF) !=
203 (
unsigned int)matfile.
namlen) {
208 const int EltSize =
sizeof(T);
209 for (
int x = 0;
x < Width;
x++)
210 for (
int y = 0; y < Height; y++)
211 if (fwrite(pBuffer+y*Width+
x, 1, EltSize, pF) !=
212 (
unsigned int)EltSize)
226 if (strlen(strFilename) == 0)
return false;
228 char* strFopenName = NULL;
229 if (!strstr(strFilename,
".mat")) {
232 sprintf(strFullFilename,
"%s.mat", strFilename);
233 strFopenName = (
char*)strFullFilename;
235 else strFopenName = (
char*)strFilename;
238 if (pImg == NULL)
return false;
240 int Width = 0, Height = 0;
243 if (pBuffer == NULL)
return false;
256 const char* strMatname,
257 const char* strFilename)
261 strMatname, strFilename);
270 sprintf(strFilename,
"%s.mat", strMatname);
287 for (nFrames = 0; ; nFrames++) {
288 if (nFrames < 10) sprintf(strFname,
"%s_00%d.mat", strPrefix,
290 else if (nFrames < 100) sprintf(strFname,
"%s_0%d.mat",
292 else sprintf(strFname,
"%s_%d.mat", strPrefix, nFrames);
293 if ((pF = fopen(strFname,
"r")) == NULL)
break;
296 if (nFrames == 0)
return false;
300 sprintf(strFname,
"%s_000.mat", strPrefix);
308 if (
i < 10) sprintf(strFname,
"%s_00%d.mat", strPrefix,
i);
309 else if (
i < 100) sprintf(strFname,
"%s_0%d.mat", strPrefix,
i);
310 else sprintf(strFname,
"%s_%d.mat", strPrefix,
i);
324 if (
i < 10) sprintf(strMatName,
"%s_00%d", strPrefix,
i);
325 else if (
i < 100) sprintf(strMatName,
"%s_0%d", strPrefix,
i);
326 else sprintf(strMatName,
"%s_%d", strPrefix,
i);
327 sprintf(strFilename,
"%s.mat", strMatName);
341 const int nFrames = InVec.size();
342 for (
int i = 0;
i < nFrames;
i++) {
343 if (
i < 10) sprintf(strMatName,
"%s_00%d", strPrefix,
i);
344 else if (
i < 100) sprintf(strMatName,
"%s_0%d", strPrefix,
i);
345 else sprintf(strMatName,
"%s_%d", strPrefix,
i);
346 sprintf(strFilename,
"%s.mat", strMatName);
#define TYPE_LONG
Definition: matlab.h:41
T * ReadBufferFromMatfile(const char *strFilename, T *pBuffer, int &Width, int &Height)
Definition: matlab.h:134
int namlen
Definition: matlab.h:111
bool ReadMatfile(CImg< T > &InImg, const char *strFilename)
Definition: matlab.h:224
bool WriteBufferToMatfile(T *pBuffer, const int Width, const int Height, const char *strMatName, const char *strFilename)
Definition: matlab.h:180
#define MAX_CHARS
Definition: matlab.h:26
bool WriteMatfile(CImg< T > &InImg, const char *strMatname)
Definition: matlab.h:267
void ReadMatheader(const char *strFilename)
#define TYPE_FLOAT
Definition: matlab.h:40
int Width() const
Definition: img.h:135
#define TYPE_BYTE
Definition: matlab.h:42
bool WriteMatfiles(const vector< CImg< T > * > &InVec, const char *strPrefix)
Definition: matlab.h:337
x
Definition: APPgetLargeConnectedEdges.m:100
#define MACH_PC
Definition: matlab.h:31
int MatlabTypeID(int *pBuffer)
Definition: matlab.h:123
int ncols
Definition: matlab.h:109
bool ReadMatfiles(CImgVec< T > &InVec, const char *strPrefix)
Definition: matlab.h:279
int type
Definition: matlab.h:107
int Height() const
Definition: img.h:138
#define W(X)
Definition: Wide.h:45
int imagf
Definition: matlab.h:110
bool Allocate(const int nFrames, const int Width, const int Height, bool bZero=false)
Definition: img.h:2450
int mrows
Definition: matlab.h:108
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
void Set_pBuffer(const T *pBuf, const int Width, const int Height, const bool bCopy=false)
IMPLEMENTATION.
Definition: img.h:592
bool IsEmpty()
Definition: img.h:2504
T * pBuffer()
Definition: img.h:148
bool IsEmpty()
Definition: img.h:190
#define MATRIX_NUM
Definition: matlab.h:48
int nFrames()
Definition: img.h:534
CImg< T > * GetImg(const int &i)
Definition: img.h:539