MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
mandelbrot_grayscale.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file mandelbrot_grayscale.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Draw a grayscale Mandelbrot Set.@EOL
7 @std C++20
8 @copyright
9 @parblock
10 Copyright (c) 1988-2015,2018 Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
18
19 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 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
27 DAMAGE.
28 @endparblock
29 @filedetails
30
31 The escape time Mandelbrot rendering algorithm delivers us a single data point, the iteration count, per pixel. Niavely this maps directly to a monochrome
32 image; however, the iteration counts used are frequently beyond 256 -- the limit for most display technology. Additionally the spatial distribution of
33 these counts is quite compressed near the edige of the Mandelbrot set leading to visually unsatsifying results. In responce a great many schemes have been
34 developed to colorize the results, and the vast majoritiy of these schemes can be broken down into standard image processing steps used in scientific image
35 analyssis. This program takes a very directrect approach and produces a deep (16-bit) greyscale TIFF image. This image may then be loaded up in your
36 favroith scietific image analysis pacakger (Mine is Fiji an ImageJ derivative), where one may then quickly play with various coloring schemes. Most of thje
37 classic ones can be reporduced in one or two steps -- a LUT and perhaps a homogenious mathematical filter. This is a great way to expore known coloring
38 schemes, and to develop new ones.
39
40 Notes:
41 - Uses a deep, greyscale image.
42 - Outputs a TIFF
43 - Optimization to avoid the main cardioid boundry and period 2 disk
44 - Uses an automatic histogram streach to expand the visual contract. I leave this step off when using Fiji.
45*/
46/*******************************************************************************************************************************************************.H.E.**/
47/** @cond exj */
48
49//--------------------------------------------------------------------------------------------------------------------------------------------------------------
50#include "ramCanvas.hpp"
51
52//--------------------------------------------------------------------------------------------------------------------------------------------------------------
53int main(void) {
54 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
55 mjr::ramCanvas1c16b theRamCanvas(7680, 7680, -2.2, 0.8, -1.5, 1.5);
56 int count;
57 const int NUMITR = mjr::ramCanvas1c16b::colorType::maxChanVal;
58
59 mjr::ramCanvas1c16b::coordFltType cr, ci;
60 std::complex<mjr::ramCanvas1c16b::coordFltType> c, z, zero(0.0, 0.0);
61 for(int y=0;y<theRamCanvas.getNumPixY();y++) {
62 for(int x=0;x<theRamCanvas.getNumPixX();x++) {
63 cr = theRamCanvas.int2realX(x);
64 ci = theRamCanvas.int2realY(y);
65 c = std::complex<mjr::ramCanvas1c16b::coordFltType>(cr, ci);
66 mjr::ramCanvas1c16b::coordFltType p = abs(c-0.25);
67 if((cr >= p-2.0*p*p+0.25) && abs(c+1.0) >= 0.25) {
68 for(z=zero,count=0; (std::norm(z)<4)&&(count<NUMITR); count++,z=z*z+c)
69 ;
70 if(count < NUMITR)
71 theRamCanvas.drawPoint(x, y, static_cast<mjr::ramCanvas1c16b::colorChanType>(count));
72 }
73 }
74 }
75 theRamCanvas.autoHistStrech();
76 theRamCanvas.writeTIFFfile("mandelbrot_grayscale.tiff");
77 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
78 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
79}
80/** @endcond */
int main(int argc, char *argv[])