MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
img_process.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file img_process.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Demo some image processing.@EOL
7 @copyright
8 @parblock
9 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
12
13 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
14
15 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17
18 3. Neither the name of the copyright holder nor the names of its contributors may be used to edorse or promote products derived from this software
19 without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 @endparblock
28*/
29/*******************************************************************************************************************************************************.H.E.**/
30/** @cond exj */
31
32//--------------------------------------------------------------------------------------------------------------------------------------------------------------
33#include "ramCanvas.hpp"
34
35//--------------------------------------------------------------------------------------------------------------------------------------------------------------
36int main(int argc, char *argv[]) {
37 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
38 //mjr::ramCanvas3c8b *aRamCanvasPtr;
39 //mjr::ramCanvas3c8b aRamCanvas;
40 mjr::ramCanvas3c8b listOcanv[16];
41 //mjr::ramCanvas4c8b listOcanv[16];
42 //mjr::ramCanvas1c16b listOcanv[16];
43 //mjr::ramCanvas1c8b listOcanv[16];
44 mjr::ramCanvas3c8b::colorType aColor;
45 int rRet;
46
47 int numFiles=argc-1;
48 for(int i=1;i<argc;i++) {
49 std::cerr << "LOADING: " << argv[i] << std::endl;
50 if((rRet=listOcanv[i-1].readTIFFfile(argv[i]))) {
51 fprintf(stderr, "ERROR(%d) reading file %s\n", rRet, argv[i]);
52 exit(1);
53 }
54 }
55
56 if(numFiles==0) {
57 std::cout << "No images provided on command line. Generateing test images" << std::endl;
58 listOcanv[0].resizeCanvas(512, 512);
59 listOcanv[0].drawFillRectangle( 0, 0, 105, 512, "white");
60 listOcanv[0].drawFillRectangle(106, 0, 205, 512, "red");
61 listOcanv[0].drawFillRectangle(206, 0, 305, 512, "green");
62 listOcanv[0].drawFillRectangle(306, 0, 405, 512, "blue");
63 listOcanv[0].drawFillRectangle(406, 0, 511, 512, "black");
64 char const *colors[5] = { "white", "red", "green", "blue", "black" };
65 for(int i=0; i<(512/32); i++)
66 listOcanv[0].drawLine(0, i*32, 512, i*32, colors[i%5]);
67 listOcanv[0].writeTIFFfile("testImage1.tiff");
68 listOcanv[0].flipTranspose();
69 listOcanv[0].writeTIFFfile("testImage2.tiff");
70 return 0;
71 }
72
73 // listOcanv[0].writeTIFFfile("in1.tiff");
74 // listOcanv[1].writeTIFFfile("in2.tiff");
75
76 // for(auto& pix : listOcanv[0])
77 // //pix.setToRed();
78 // pix.tfrmNot();
79
80 /* **************************************************************************************************************************************************************** */
81 /* **************************************************************************************************************************************************************** */
82 /* Convolution. Output image as conv.tiff. */
83 /* **************************************************************************************************************************************************************** */
84
85 // To use convolving, we need a kernel
86 // double edgeDetect1_3[9] = { 1, 0, -1, 0, 0, 0, -1, 0, 1};
87 // double edgeDetect2_3[9] = { 0, 1, 0, 1, -4, 1, 0, 1, 0};
88 // double edgeDetect3_3[9] = {-1, -1, -1, -1, 8, -1, -1, -1, -1};
89 // double sharpen_3[9] = { 0, -1, 0, -1, 5, -1, 0, -1, 0};
90 // double boxBlur_3[9] = { 1, 1, 1, 1, 1, 1, 1, 1, 1}; // (d=9)
91 // double gaussianBlur_3[9] = { 1, 2, 1, 2, 4, 2, 1, 2, 1}; // (d=16)
92 // double gaussianBlur_5[25] = {1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, 36, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1}; // (d=256)
93 // double unsharpMmasking_5[25] = {1, 4, 6, 4, 1, 4, 16, 24, 16, 4, 6, 24, -476, 24, 6, 4, 16, 24, 16, 4, 1, 4, 6, 4, 1}; // (d=-256)
94
95 double kernel[51*51];
96 listOcanv[0].computeConvolutionMatrixGausian(kernel, 9, 10);
97 //listOcanv[0].computeConvolutionMatrixBox(kernel, 9);
98
99 std::cerr << "CONVOLUTION STARTING" << std::endl;
100 listOcanv[0].convolution(kernel, 9, 9, 1.0);
101 //listOcanv[0].convolution(edgeDetect2_3, 3, 3, 1.0);
102 //listOcanv[0].convolution(gaussianBlur_5, 5, 5, 256);
103 listOcanv[0].writeTIFFfile("testImage1_c.tiff");
104
105 /* **************************************************************************************************************************************************************** */
106 /* **************************************************************************************************************************************************************** */
107 /* Hide the second image in the first. Outputs the given images as in1.tiff and in2.tiff. Outputs the combined image as cmb.tiff. */
108 /* **************************************************************************************************************************************************************** */
109 // listOcanv[0].writeTIFFfile("in1.tiff");
110 // listOcanv[1].writeTIFFfile("in2.tiff");
111 // listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmAnd, mjr::ramCanvas3c8b::colorType(0xF0, 0xF0, 0xF0));
112 // listOcanv[1].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmShiftR, mjr::ramCanvas3c8b::colorType(4, 4, 4));
113 // listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmOr, listOcanv[1]);
114 // listOcanv[0].writeTIFFfile("cmb.tiff");
115
116 /* **************************************************************************************************************************************************************** */
117 /* **************************************************************************************************************************************************************** */
118 /* Extract two images that have been combined. */
119 /* **************************************************************************************************************************************************************** */
120 // listOcanv[1].reallocCanvas(listOcanv[0].getNumPixX(), listOcanv[0].getNumPixY());
121 // listOcanv[1].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmCopy, listOcanv[0]);
122 // listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmAnd, mjr::ramCanvas3c8b::colorType(0xF0, 0xF0, 0xF0));
123 // listOcanv[1].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmShiftL, mjr::ramCanvas3c8b::colorType(4, 4, 4));
124 // listOcanv[0].writeTIFFfile("out1.tiff");
125 // listOcanv[1].writeTIFFfile("out2.tiff");
126
127 /* **************************************************************************************************************************************************************** */
128 /* **************************************************************************************************************************************************************** */
129 /* Various homogenious transformations */
130 /* **************************************************************************************************************************************************************** */
131 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmStep, mjr::ramCanvas3c8b::colorType(150, 150, 150), mjr::ramCanvas3c8b::colorType(200, 200, 200));
132 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmSaw, mjr::ramCanvas3c8b::colorType(150, 150, 150), mjr::ramCanvas3c8b::colorType(200, 200, 200));
133 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmShiftL, mjr::ramCanvas3c8b::colorType(4, 4, 4));
134 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmShiftR, mjr::ramCanvas3c8b::colorType(4, 4, 4));
135 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmAnd, mjr::ramCanvas3c8b::colorType(0x00, 0xFF, 0x00));
136 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmOr, mjr::ramCanvas3c8b::colorType(0xFF, 0x00, 0x00));
137 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmXor, mjr::ramCanvas3c8b::colorType(0xF0, 0x0F, 0x0F));
138 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmInvert);
139 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmNot);
140 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmStdPow, 0.7);
141 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmStdPow, 0.9, 0.8, 0.7);
142 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmLinearGreyLevelScale, 2.0, 150.0);
143 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmLinearGreyLevelScale, 2, 150, 0, 0, 1, 0); // no workie
144 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmDirac, mjr::ramCanvas3c8b::colorType(0xF0, 0x0F, 0x0F));
145 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmFuzzyDirac, mjr::ramCanvas3c8b::colorType(0xF0, 0x0F, 0x0F), mjr::ramCanvas3c8b::colorType(0x0F, 0x0F, 0x0F));
146 //listOcanv[0].applyHomoPixTfrm(&mjr::ramCanvas3c8b::colorType::tfrmDiracTot, mjr::ramCanvas3c8b::colorType(0xF0, 0x0F, 0x0F));
147 //listOcanv[0].writeTIFFfile("img_process.tiff");
148
149 /* **************************************************************************************************************************************************************** */
150 /* **************************************************************************************************************************************************************** */
151 /* Various canvas combination functions */
152 /* **************************************************************************************************************************************************************** */
153 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmXor, listOcanv[1]);
154 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmAnd, listOcanv[1]);
155 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmOr, listOcanv[1]);
156 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmCopy, listOcanv[1]);
157 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmAbsDiff, listOcanv[1]);
158 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmSqDiff, listOcanv[1]);
159 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmSum, listOcanv[1]);
160 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmSumClp, listOcanv[1]);
161 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmDiv, listOcanv[1]);
162 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMult, listOcanv[1]);
163 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMultClp, listOcanv[1]);
164 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMean, listOcanv[1]);
165 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMean, listOcanv[1]);
166 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmGmean, listOcanv[1]);
167 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmGmeanClp, listOcanv[1]);
168 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmDiff, listOcanv[1]);
169 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmDiffClp, listOcanv[1]);
170 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMod, listOcanv[1]);
171 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMaxL, listOcanv[1]);
172 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMinL, listOcanv[1]);
173 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMax, listOcanv[1]);
174 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMin, listOcanv[1]);
175 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMean, listOcanv[1], 10, 20);
176 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMean, listOcanv[1], 20, 10, 50, 40);
177 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMean, listOcanv[1], 10, 20, 50, 60, 100, 100);
178 //listOcanv[0].combineRamCanvasBinOp(&mjr::ramCanvas3c8b::colorType::tfrmMean, listOcanv[1], 400, 450, 150, 60, 100, 100);
179 //listOcanv[0].writeTIFFfile("img_process.tiff");
180
181 /* **************************************************************************************************************************************************************** */
182 /* **************************************************************************************************************************************************************** */
183 /* Multi-image statstical combinations. */
184 /* **************************************************************************************************************************************************************** */
185 //aRamCanvas = ramCanvas3c8b(listOcanv[0].getNumPixX(), listOcanv[0].getNumPixY());
186 //aRamCanvas.combineRamCanvasMean(listOcanv, numFiles);
187 //aRamCanvas.writeTIFFfile("img_process.tiff");
188
189 /* **************************************************************************************************************************************************************** */
190 /* **************************************************************************************************************************************************************** */
191 /* Rotate, Scale, Reflect */
192 /* **************************************************************************************************************************************************************** */
193 //listOcanv[0].flipHorz();
194 //listOcanv[0].flipVert();
195 //listOcanv[0].flipTranspose();
196 //listOcanv[0].rotate90CW();
197 //listOcanv[0].rotate90CCW();
198 //listOcanv[0].rotate180();
199 //listOcanv[0].scaleUpProximal(2);
200 //listOcanv[0].scaleDown1pt(2);
201 //listOcanv[0].scaleDownMax(2);
202 //listOcanv[0].scaleDownMean(2);
203 //listOcanv[0].writeTIFFfile("img_process.tiff");
204 //listOcanv[0].cropCanvas(10, 10, 200, 200);
205 //listOcanv[0].resizeCanvas(400, 300, 30, 5);
206 //listOcanv[0].writeTIFFfile("img_process.tiff");
207
208 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
209 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
210
211 return 0;
212}
213/** @endcond */
int main(int argc, char *argv[])