blob: 8afc44ed038d2f67d49f1adce81710811914d441 [file] [log] [blame]
Austin Schuh8c794d52019-03-03 21:17:37 -08001/*
2 #
3 # File : use_tinymatwriter.cpp
4 # ( C++ source file )
5 #
6 # Description : Example of use for the CImg plugin 'plugins/tinymatwriter.h'.
7 # This file is a part of the CImg Library project.
8 # ( http://cimg.eu )
9 #
10 # Copyright : Jan W. Krieger
11 # ( https://github.com/jkriege2 )
12 #
13 # License : CeCILL v2.0
14 # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
15 #
16 # This software is governed by the CeCILL license under French law and
17 # abiding by the rules of distribution of free software. You can use,
18 # modify and/ or redistribute the software under the terms of the CeCILL
19 # license as circulated by CEA, CNRS and INRIA at the following URL
20 # "http://www.cecill.info".
21 #
22 # As a counterpart to the access to the source code and rights to copy,
23 # modify and redistribute granted by the license, users are provided only
24 # with a limited warranty and the software's author, the holder of the
25 # economic rights, and the successive licensors have only limited
26 # liability.
27 #
28 # In this respect, the user's attention is drawn to the risks associated
29 # with loading, using, modifying and/or developing or reproducing the
30 # software by the user in light of its specific status of free software,
31 # that may mean that it is complicated to manipulate, and that also
32 # therefore means that it is reserved for developers and experienced
33 # professionals having in-depth computer knowledge. Users are therefore
34 # encouraged to load and test the software's suitability as regards their
35 # requirements in conditions enabling the security of their systems and/or
36 # data to be ensured and, more generally, to use and operate it in the
37 # same conditions as regards security.
38 #
39 # The fact that you are presently reading this means that you have had
40 # knowledge of the CeCILL license and that you accept its terms.
41 #
42*/
43
44/*
45 This Matlab/Octave script tests the output:
46 clear all
47 more off
48
49 subplot(2,2,1)
50 load("mat432.mat", "-v6")
51 disp('mat432.mat: CImg_image=')
52 disp(CImg_image)
53 imagesc(CImg_image(:,:,1))
54 colorbar
55
56 subplot(2,2,2)
57 load("mat432i16.mat", "-v6")
58 disp('mat432i16.mat: CImg_image=')
59 disp(CImg_image)
60 imagesc(double(CImg_image(:,:,2)))
61 colorbar
62
63 subplot(2,2,3)
64 load("matb.mat", "-v6")
65 disp('matb.mat: CImg_image=')
66 disp(CImg_image)
67 imagesc(CImg_image(:,:,4))
68 colorbar
69*/
70
71#include <iostream>
72#include <stdio.h>
73#include "tinymatwriter.h"
74#include <cmath>
75
76#define cimg_plugin "plugins/tinymatwriter.h"
77#include "../CImg.h"
78
79using namespace std;
80using namespace cimg_library;
81
82int main(int argc, const char** argv) {
83
84 double mat432[4*3*2]= {
85 1,2,3,
86 4,5,6,
87
88 10,20,30,
89 40,50,60,
90
91 100,200,300,
92 400,500,600,
93
94 1000,2000,3000,
95 4000,5000,6000,
96 };
97
98 int16_t mat432i16[4*3*2]= {
99 1,2,3,
100 4,5,6,
101
102 10,20,30,
103 40,50,60,
104
105 100,200,300,
106 400,500,600,
107
108 1000,-2000,3000,
109 -4000,5000,-6000,
110 };
111
112 // a boolean matrix
113 bool matb[4*3*2] = {
114 true,false,true,
115 false,true,false,
116
117 true,true,true,
118 false,false,false,
119
120 true,false,true,
121 true,false,true,
122
123 true,true,false,
124 false,true,true
125 };
126
127 cimg_library::CImg<double> ciD(mat432, 3,2,4);
128 cimg_library::CImg<int16_t> ciI16(mat432i16, 3,2,4);
129 cimg_library::CImg<bool> ciB(matb, 3,2,4);
130
131 ciD.save_tinymat("mat432.mat");
132 ciI16.save_tinymat("mat432i16.mat");
133 ciB.save_tinymat("matb.mat");
134 return 0;
135}