Skip to content

Commit

Permalink
First pass at pixel filter stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
richmit committed Feb 22, 2025
1 parent 7d4d382 commit 88f5a81
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 158 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ set(MRASTER_INCLUDES "lib/MRcolor.hpp"
"lib/hersheyFont.hpp"
"lib/MRpoint2d.hpp"
"lib/ramCanvas.hpp"
"lib/ramCanvasPixelFilters.hpp"
"lib/ramCanvasTpl.hpp")
add_library(MRaster INTERFACE ${MRASTER_INCLUDES})
target_include_directories(MRaster INTERFACE "${PROJECT_SOURCE_DIR}/lib")
Expand Down
3 changes: 2 additions & 1 deletion docs/roadmap.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/roadmap.org
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ end up on this list.

In no particular order:

- Use callables for pixel transforms
- Homo transforms
- +Complex abs/arg greyscale transform+ DONE.
- +2D plane Color Schemes+ DONE
Expand Down
6 changes: 3 additions & 3 deletions examples/convertRawToTIFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ int main(int argc, char *argv[]) {

// We create a converter object for the *two* file write methods below. This converter will transform the 32-bit floating point channels into 8-bit
// unsigned integer channels.
mjr::ramCanvas3c32F::rcConverterRGBbyte<mjr::ramCanvas3c32F> rcConv(theRamCanvas);
mjr::ramCanvasPixelFilter::RGBbyte<mjr::ramCanvas3c32F> pxFilt(theRamCanvas);

ret = theRamCanvas.writeRAWfile("foo.mrw", rcConv);
ret = theRamCanvas.writeRAWfile("foo.mrw", pxFilt);
if (ret != 0) {
std::cout << "ERROR(writeRAWfile): " << ret << std::endl;
return ret;
}

// Note: For the more complex writeTIFFfile() method, the markAlpha argument is not optional.
ret = theRamCanvas.writeTIFFfile("foo.tiff", rcConv, false);
ret = theRamCanvas.writeTIFFfile("foo.tiff", pxFilt);
if (ret != 0) {
std::cout << "ERROR(writeTIFFfile): " << ret << std::endl;
return ret;
Expand Down
23 changes: 10 additions & 13 deletions examples/newton_orbits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "ramCanvas.hpp"

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef mjr::ramCanvas1c16b::rcConverterMonoIntensity<mjr::ramCanvas3c16b, mjr::colChanI16> g2mono;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
int main(void) {
std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
constexpr int MaxCount = 255;
constexpr double Tol = .0001;
constexpr int IMGSIZ = 7680;
constexpr int IMGSIZ = 7680/4;
std::complex<double> r1( 1.0, 0.0);
std::complex<double> r2(-0.5, sin(2*std::numbers::pi/3));
std::complex<double> r3(-0.5, -sin(2*std::numbers::pi/3));
Expand All @@ -59,15 +56,15 @@ int main(void) {
count++;
}

mjr::ramCanvas3c16b::colorType cDelta;
decltype(theRamCanvas)::colorType cDelta;
if(abs(z-r1) <= Tol)
cDelta = mjr::ramCanvas3c16b::colorType(1, 0, 0);
cDelta = decltype(theRamCanvas)::colorType(1, 0, 0);
else if(abs(z-r2) <= Tol)
cDelta = mjr::ramCanvas3c16b::colorType(0, 1, 0);
cDelta = decltype(theRamCanvas)::colorType(0, 1, 0);
else if(abs(z-r3) <= Tol)
cDelta = mjr::ramCanvas3c16b::colorType(0, 0, 1);
cDelta = decltype(theRamCanvas)::colorType(0, 0, 1);
else
cDelta = mjr::ramCanvas3c16b::colorType(0, 0, 0);
cDelta = decltype(theRamCanvas)::colorType(0, 0, 0);

for(int i=0; i<count; i++) {
int zri = theRamCanvas.real2intX(std::real(orbit[i]));
Expand All @@ -77,13 +74,13 @@ int main(void) {
}
}
}
theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas3c16b::colorType::tfrmLn, 11271.0);
theRamCanvas.applyHomoPixTfrm(&decltype(theRamCanvas)::colorType::tfrmLn, 11271.0);
theRamCanvas.autoMaxHistStrechRGB();
theRamCanvas.writeTIFFfile("newton_orbits_col.tiff");

theRamCanvas.rotate90CW();
g2mono rcFilt(theRamCanvas);
theRamCanvas.writeTIFFfile("newton_orbits_mon.tiff", rcFilt, false);
auto tf1 = mjr::ramCanvasPixelFilter::MonoIntensity<decltype(theRamCanvas), mjr::colChanI8>(theRamCanvas);
auto tf2 = mjr::ramCanvasPixelFilter::Rotate90CW<decltype(tf1)>(tf1);
theRamCanvas.writeTIFFfile("newton_orbits_mon.tiff", tf2);

std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
Expand Down
16 changes: 6 additions & 10 deletions examples/peterdejongEAAO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
int main(void) {
std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
const int IMXSIZ = 7680/1;
const int IMYSIZ = 7680/1;
const int IMXSIZ = 7680/4;
const int IMYSIZ = 7680/4;

const int n = 8;
const double a = 1.4;
Expand Down Expand Up @@ -112,14 +112,10 @@ int main(void) {
p4canvas.drawPoint(xi, yi, decltype(p1canvas)::colorType::csCColdeFireRamp::c(r*r));
}
}
p1canvas.scaleDownMean(4);
p2canvas.scaleDownMean(4);
p3canvas.scaleDownMean(4);
p4canvas.scaleDownMean(4);
p1canvas.writeTIFFfile("peterdejongEAAO_00_c1.tiff");
p2canvas.writeTIFFfile("peterdejongEAAO_00_c2.tiff");
p3canvas.writeTIFFfile("peterdejongEAAO_00_c3.tiff");
p4canvas.writeTIFFfile("peterdejongEAAO_00_c4.tiff");
p1canvas.writeTIFFfile("peterdejongEAAO_00_c1.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p1canvas), 4>(p1canvas));
p2canvas.writeTIFFfile("peterdejongEAAO_00_c2.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p2canvas), 4>(p2canvas));
p3canvas.writeTIFFfile("peterdejongEAAO_00_c3.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p3canvas), 4>(p3canvas));
p4canvas.writeTIFFfile("peterdejongEAAO_00_c4.tiff", mjr::ramCanvasPixelFilter::ScaleDownMean<decltype(p4canvas), 4>(p4canvas));

std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
Expand Down
13 changes: 8 additions & 5 deletions examples/pickoverPopcorn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// This is *identical* to what we did in sic.cpp -- just way shorter.
typedef mjr::ramCanvas1c16b::rcConverterColorScheme<mjr::ramCanvas1c16b, mjr::color3c8b, mjr::color3c8b::csCCfractal0RYBCW, true, 10, 0> g2rgb8;
typedef mjr::ramCanvasPixelFilter::ColorSchemeOnChan<mjr::ramCanvas1c16b, mjr::color3c8b, mjr::color3c8b::csCCfractal0RYBCW> g2rgb8;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
int main(void) {
std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
const int IMXSIZ = 7680/2;
const int IMYSIZ = 4320/2;
const int IMXSIZ = 7680/8;
const int IMYSIZ = 4320/8;
const int NUMITR = 100;
const int spanx = 1;
const int spany = 1;
Expand Down Expand Up @@ -74,8 +74,11 @@ int main(void) {
}
}
hstRamCanvas.writeTIFFfile("pickoverPopcornCNT.tiff");
g2rgb8 rcFilt(hstRamCanvas);
hstRamCanvas.writeTIFFfile("pickoverPopcornCOL.tiff", rcFilt, false);
g2rgb8 pxFilt(hstRamCanvas);
hstRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmMultClamp, 10);
hstRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmMin, mjr::color3c8b::csCCfractal0RYBCW::numC-1);
hstRamCanvas.autoHistStrech();
hstRamCanvas.writeTIFFfile("pickoverPopcornCOL.tiff", pxFilt);
std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
return 0;
Expand Down
11 changes: 5 additions & 6 deletions examples/sic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ std::vector<std::array<mjr::ramCanvas1c16b::coordFltType, 12>> params {
};

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// This is *identical* to what we did in pickoverPopcorn.cpp -- just way shorter. It is longer still because we don't make
// this a subclass of ramCanvasTpl::rcConverterHomoBase in order to illustrate how to implement a RC converter from scratch.
// Also note we didn't need to DIY the color gradient with cmpRGBcornerDGradiant() as this gradient (0RYBCW) is available as
// a pre-built color scheme: csCCfractal0RYBCW.
// This is *identical* to what we did in pickoverPopcorn.cpp -- just way shorter. It is longer still because we don't make this a subclass of
// mjr::ramCanvasPixelFilter::HomoBase in order to illustrate how to implement a RC pixel filter from scratch. Also note we didn't need to DIY the color
// gradient with cmpRGBcornerDGradiant() as this gradient (0RYBCW) is available as a pre-built color scheme: csCCfractal0RYBCW.
class g2rgb8 {
private:
mjr::ramCanvas1c16b& attachedRC;
Expand Down Expand Up @@ -171,8 +170,8 @@ int main(void) {
cRamCanvas.writeTIFFfile("sicC_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff");
We have a better way. One that dosen't require the RAM to create a brand new canvas. We can use
the filter option of writeTIFFfile! */
g2rgb8 rcFilt(theRamCanvas, maxII);
theRamCanvas.writeTIFFfile("sicCC_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff", rcFilt, false);
g2rgb8 pxFilt(theRamCanvas, maxII);
theRamCanvas.writeTIFFfile("sicCC_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff", pxFilt, false);
}
std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
Expand Down
13 changes: 6 additions & 7 deletions examples/simone_attractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@
#include "MRMathSTR.hpp"

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// typedef mjr::ramCanvas3c8b rct;
// typedef rct::colorType ct;

typedef mjr::ramCanvas1c16b::rcConverterColorScheme<mjr::ramCanvas1c16b, mjr::color3c8b, mjr::color3c8b::csCCfractal0RYBCW, true, 100, 0> g2rgb8;
typedef mjr::ramCanvasPixelFilter::ColorSchemeOnChan<mjr::ramCanvas1c16b, mjr::color3c8b, mjr::color3c8b::csCCfractal0RYBCW> g2rgb8;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
std::vector<std::array<mjr::ramCanvas1c16b::coordFltType, 5>> params {
/* a b x0 y0 maxitr */
{ 3.69, 4.511, 0.0, 0.0, 100000000}, // 0
{ 3.64, 1.710, 0.0, 0.0, 100000000}, // 1
//{ 3.64, 1.710, 0.0, 0.0, 100000000}, // 1
};

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -89,9 +86,11 @@ int main(void) {

theRamCanvas.autoHistStrech();
theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmLn1);
g2rgb8 rcFilt(theRamCanvas);
//theRamCanvas.applyHomoPixTfrm(&mjr::ramCanvas1c16b::colorType::tfrmPow, 0.8);
theRamCanvas.autoHistStrech();
g2rgb8 pxFilt(theRamCanvas);
std::cout << "ITER(" << j << "): " << "TIFF" << std::endl;
theRamCanvas.writeTIFFfile("simone_attractor_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff", rcFilt, true);
theRamCanvas.writeTIFFfile("simone_attractor_" + mjr::math::str::fmt_int(j, 2, '0') + ".tiff", pxFilt);
}
std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions lib/MRcolorTpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5207,7 +5207,7 @@ namespace mjr {
(redChanIdx != alphaChanIdx) &&
(greenChanIdx != blueChanIdx) &&
(greenChanIdx != alphaChanIdx) &&
(blueChanIdx != alphaChanIdx)))) // Chans can't be teh same if non-negative
(blueChanIdx != alphaChanIdx)))) // Chans can't be the same if non-negative
inline std::ostream&
operator<< (std::ostream &out, colorTpl<clrChanT, numChan> const& color) {
// MJR BUG NOTE operator<<: Will fail if 'char' is bigger than uint64_t -- I shudder to imagine a future that might bring such a condition..
Expand Down Expand Up @@ -5242,7 +5242,7 @@ namespace mjr {
(redChanIdx != alphaChanIdx) &&
(greenChanIdx != blueChanIdx) &&
(greenChanIdx != alphaChanIdx) &&
(blueChanIdx != alphaChanIdx)))) // Chans can't be teh same if non-negative
(blueChanIdx != alphaChanIdx)))) // Chans can't be the same if non-negative
inline bool
operator!= (colorTpl<clrChanT, numChan> const& color1, colorTpl<clrChanT, numChan> const& color2) {
return color1.isNotEqual(color2);
Expand Down
Loading

0 comments on commit 88f5a81

Please sign in to comment.