mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-11-15 10:05:47 +08:00
added CImg interface (header-only) + examples
some corrections for OpenCV examples
This commit is contained in:
parent
e087f40870
commit
57e8fb3362
1
.gitignore
vendored
1
.gitignore
vendored
@ -94,3 +94,4 @@ moc_predefs.h
|
||||
Sicherungskopie_*
|
||||
/examples/simpletest_rgbimageplot_opencv/opencv
|
||||
/build
|
||||
/*.10-pre1
|
||||
|
@ -36,7 +36,7 @@ This software is licensed under the term of the [GNU Lesser General Public Licen
|
||||
- contour plots
|
||||
- geometric forms/annotations
|
||||
- can be easily extended by deriving a new graph from JKQTPPlotElement or JKQTPPlotObject
|
||||
- optional: OpenCV interface
|
||||
- optional: OpenCV, CImg interfaces
|
||||
- CMake-based build system
|
||||
- extensive set of [Examples/Tutorials](./examples/README.md)
|
||||
- extensive doxygen-generated [Documentation](http://jkriege2.github.io/JKQtPlotter/index.html)
|
||||
|
49
cmake/FindCImg.cmake
Normal file
49
cmake/FindCImg.cmake
Normal file
@ -0,0 +1,49 @@
|
||||
# - Try to find CImg lib
|
||||
#
|
||||
# CIMG_FOUND - system has CImg lib
|
||||
# CIMG_INCLUDE_DIR - the CImg include directory
|
||||
|
||||
|
||||
macro(_cimg_check_path)
|
||||
|
||||
if(EXISTS "${CIMG_INCLUDE_DIR}/CImg.h")
|
||||
set(CImg_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
if(NOT CImg_FOUND)
|
||||
message(STATUS "CImg include path was specified but no CImg.h file was found: ${CIMG_INCLUDE_DIR}")
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
||||
if(NOT CIMG_INCLUDE_DIR)
|
||||
message(STATUS "CImg: trying to locate CImg library")
|
||||
find_path(CIMG_INCLUDE_DIR NAMES CImg.h
|
||||
PATHS
|
||||
${CImg_DIR}
|
||||
${CImg_DIR}/include
|
||||
${CImg_DIR}/cimg
|
||||
${CImg_DIR}/include/cimg
|
||||
${CImg_DIR}/cimg/include
|
||||
${CMAKE_INSTALL_PREFIX}
|
||||
${CMAKE_INSTALL_PREFIX}/cimg
|
||||
${CMAKE_INSTALL_PREFIX}/include
|
||||
${CMAKE_INSTALL_PREFIX}/include/cimg
|
||||
${CMAKE_INSTALL_PREFIX}/cimg/include
|
||||
${KDE4_INCLUDE_DIR}
|
||||
${KDE4_INCLUDE_DIR}/cimg
|
||||
${KDE4_INCLUDE_DIR}/include
|
||||
${KDE4_INCLUDE_DIR}/include/cimg
|
||||
${KDE4_INCLUDE_DIR}/cimg/include
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
if(CIMG_INCLUDE_DIR)
|
||||
_cimg_check_path()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(CImg DEFAULT_MSG CIMG_INCLUDE_DIR CImg_FOUND)
|
||||
|
||||
mark_as_advanced(CIMG_INCLUDE_DIR)
|
@ -113,12 +113,18 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
<tr><td> \image html rgbimageplot_small.png
|
||||
<td> \subpage JKQTPlotterRGBImagePlot
|
||||
<td> `JKQTPColumnRGBMathImage` <br> image data in a C-style row-major array, not using internal datastore <br> RGB/CMY color compositing
|
||||
<tr><td> \image html imageplot_opencv_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotOpenCV
|
||||
<tr><td> \image html imageplot_opencv_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotOpenCV
|
||||
<td> `JKQTPColumnMathImage` <br> image data copied from OpenCV cv::Mat-structure into a single column of the internal datastore
|
||||
<tr><td> \image html rgbimageplot_opencv_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotRGBOpenCV
|
||||
<tr><td> \image html rgbimageplot_opencv_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotRGBOpenCV
|
||||
<td> `JKQTPColumnRGBMathImage` <br> image data copied from OpenCV cv::Mat-structure into three columns of the internal datastore <br> inverted coordinate axes
|
||||
<tr><td> \image html imageplot_cimg_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotcimg
|
||||
<td> `JKQTPColumnMathImage` <br> image data copied from CImg datastructure into a single column of the internal datastore
|
||||
<tr><td> \image html rgbimageplot_cimg_small.png
|
||||
<td> \subpage JKQTPlotterImagePlotRGBcimg
|
||||
<td> `JKQTPColumnRGBMathImage` <br> image data copied from CImg datastructure into three columns of the internal datastore <br> inverted coordinate axes
|
||||
<tr><td> \image html contourplot_small.png
|
||||
<td> \subpage JKQTPlotterContourPlot
|
||||
<td> `JKQTPColumnContourPlot` <br> image data edited inside JKQTPDatastore
|
||||
|
@ -151,9 +151,13 @@ classes.
|
||||
|
||||
\see \ref JKQTPlotterBasicJKQTPDatastore for a detailed description of how to use this class for data management!
|
||||
|
||||
\defgroup jkqtpopencvinterface OpenCV Interfaceing Tools
|
||||
\defgroup jkqtpexternalinterfaces Interfaces To Other Libraries
|
||||
\ingroup jkqtpdatastorage
|
||||
|
||||
|
||||
\defgroup jkqtpinterfaceopencv OpenCV Interfaceing Tools
|
||||
\ingroup jkqtpexternalinterfaces
|
||||
|
||||
Classes and functions in this group allow JKQTPlotter to directly work with <a href="https://opencv.org/">OpenCV</a> data structures.
|
||||
|
||||
Examples:
|
||||
@ -166,6 +170,25 @@ The OpenCV-binding itself is header-only, and NOT compiled into the JKQtPlotter
|
||||
The CMake-build system of JKQtPlotter (and its examples) is compatible with both OpenCV 3.4.x and 4.x and uses the standard `find_package(OpenCV)` facilities provided by OpenCV to compile and bind against that library.
|
||||
If you want to build the OpenCV-based JKQtPlotter examples (see list above), you either have to ensure that CMake finds OpenCV by itself (i.e. somewhere in the default search paths), or you can set the CMake variable `OpenCV_DIR` so it points to the OpenCV directory before configuring JKQtPlotter.
|
||||
|
||||
|
||||
|
||||
\defgroup jkqtpinterfacecimg CImg Interfaceing Tools
|
||||
\ingroup jkqtpexternalinterfaces
|
||||
|
||||
Classes and functions in this group allow JKQTPlotter to directly work with <a href="http://cimg.eu/">CImg</a> data structures <a href="http://cimg.eu/reference/structcimg__library_1_1CImg.html">CImg<T>></a>.
|
||||
|
||||
Examples:
|
||||
- \ref JKQTPlotterImagePlotCImg
|
||||
- \ref JKQTPlotterImagePlotRGBCImg
|
||||
.
|
||||
|
||||
The CImg-binding itself is header-only (as CImg is itself), and NOT compiled into the JKQtPlotter libraries. Therefore you can simply include the header and use the facilities provided by it.
|
||||
|
||||
The CMake-build system of JKQtPlotter (and its examples) provides facilities to allow for `find_package(CImg)` to compile against that library.
|
||||
If you want to build the CImg-based JKQtPlotter examples (see list above), you either have to ensure that CMake finds CImg by itself (i.e. somewhere in the default search paths, e.g. `CMAKE_INSTALL_PREFIX`), or you can set the CMake variable `CImg_DIR` so it points to the directory of the `CImg.h` file, or before configuring JKQtPlotter.
|
||||
|
||||
|
||||
|
||||
\defgroup jkqtpplottersupprt Support Classes and Functions
|
||||
\ingroup jkqtplotter
|
||||
|
||||
@ -492,7 +515,7 @@ Examples:
|
||||
<td>\image html JKQTPMathImageBaseModifyNone_small.png
|
||||
<td> JKQTPMathImage, JKQTPColumnMathImage
|
||||
<tr>
|
||||
<td>\image html rgbimageplot_opencv_small.png
|
||||
<td>\image html rgbimageplot_cimg_small.png
|
||||
<td> JKQTPRGBMathImage, JKQTPColumnRGBMathImage
|
||||
</table>
|
||||
|
||||
|
@ -43,7 +43,9 @@
|
||||
- \ref jkqtplotter_imagelots_contour "contour plots"
|
||||
- \ref jkqtplotter_geoplots "geometric forms/annotations"
|
||||
- can be easily extended by deriving a new graph from JKQTPPlotElement or JKQTPPlotObject
|
||||
- <b>\ref jkqtpopencvinterface "optional: OpenCV interface"</b>
|
||||
- <b>OPTIONAL: Interfaces to external libraries</b>
|
||||
- \ref jkqtpinterfaceopencv "OpenCV interface"
|
||||
- \ref jkqtpinterfacecimg "CImg interface"
|
||||
- <b>integrated LaTeX parser/renderer JKQTMathText :</b>
|
||||
- pure C++
|
||||
- no dependencies in particular no installed LaTeX required
|
||||
|
@ -30,7 +30,8 @@ Changes, compared to \ref page_whatsnew_V2018_08 "v2018.08" include:
|
||||
<li> new: added JKQTPSingleColumnSymbolsGraph for single-column data, e.g. drawn as (random) scatter or bee-swarm or rug plots </li>
|
||||
<li> new: stacked barcharts with JKQTPBarVerticalStackableGraph, JKQTPBarHorizontalStackableGraph </li>
|
||||
<li> new: use/support of C++11 features (e.g. \c std::function<> and lambda functions in JKQTPXFunctionLineGraph / JKQTPYFunctionLineGraph )</li>
|
||||
<li> new: \ref jkqtpopencvinterface "optional OpenCV interface" </li>
|
||||
<li> new: \ref jkqtpinterfaceopencv "optional OpenCV interface" </li>
|
||||
<li> new: \ref jkqtpinterfacecimg "optional CImg interface" </li>
|
||||
<li> new: \ref jkqtpplotter_styling "Styling System for JKQTPlotter" </li>
|
||||
<li> new: added debugging option, which surrounds different regions with visible rectangles (JKQTBasePlotter::enableDebugShowRegionBoxes() ) </li>
|
||||
<li> new: frames (plot viewport, key/legend ...) may be rounded off at the corners</li>
|
||||
|
@ -33,6 +33,7 @@ add_subdirectory(imageplot_userpal)
|
||||
add_subdirectory(imageplot_modifier)
|
||||
add_subdirectory(imageplot_nodatastore)
|
||||
add_subdirectory(imageplot_opencv)
|
||||
add_subdirectory(imageplot_cimg)
|
||||
add_subdirectory(impulsesplot)
|
||||
add_subdirectory(logaxes)
|
||||
add_subdirectory(multiplot)
|
||||
@ -42,6 +43,7 @@ add_subdirectory(paramscatterplot_image)
|
||||
add_subdirectory(parsedfunctionplot)
|
||||
add_subdirectory(rgbimageplot)
|
||||
add_subdirectory(rgbimageplot_opencv)
|
||||
add_subdirectory(rgbimageplot_cimg)
|
||||
add_subdirectory(rgbimageplot_qt)
|
||||
add_subdirectory(simpletest)
|
||||
add_subdirectory(speed)
|
||||
|
@ -48,6 +48,8 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/rgbimageplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot) | [Simple 3-channel Math RGB/CMY Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot) | `JKQTPColumnRGBMathImage` <br> image data in a C-style row-major array, not using internal datastore <br> RGB/CMY color compositing |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_opencv_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_opencv) | [1-channel OpenCV cv::Mat Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_opencv) | `JKQTPColumnMathImage` <br> image data copied from OpenCV cv::Mat-structure into a single column of the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/rgbimageplot_opencv_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_opencv) | [RGB OpenCV cv::Mat Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_opencv) | `JKQTPColumnRGBMathImage` <br> image data copied from OpenCV cv::Mat-structure into three columns <br> inverted coordinate axesof the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_cimg_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_cimg) | [1-channel CImg Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_cimg) | `JKQTPColumnMathImage` <br> image data copied from cimg CImg<T>-structure into a single column of the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/rgbimageplot_cimg_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_cimg) | [RGB cimg Image Plot](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_cimg) | `JKQTPColumnRGBMathImage` <br> image data copied from CImg image datastructure into three columns <br> inverted coordinate axesof the internal datastore |
|
||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/contourplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/contourplot) | [Contour Plots](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/contourplot) | `JKQTPColumnContourPlot` <br> image data edited inside JKQTPDatastore |
|
||||
|
||||
|
||||
|
33
examples/imageplot_cimg/CMakeLists.txt
Normal file
33
examples/imageplot_cimg/CMakeLists.txt
Normal file
@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
find_package( CImg )
|
||||
if(CImg_FOUND)
|
||||
|
||||
set(EXAMPLE_NAME imageplot_cimg)
|
||||
set(EXENAME jkqtptest_${EXAMPLE_NAME})
|
||||
|
||||
message( STATUS ".. Building Example ${EXAMPLE_NAME}" )
|
||||
|
||||
# Set up source files
|
||||
set(SOURCES ${EXAMPLE_NAME}.cpp)
|
||||
set(HEADERS )
|
||||
set(RESOURCES )
|
||||
set(UIS )
|
||||
|
||||
add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS})
|
||||
target_include_directories(${EXENAME} PRIVATE ../../lib)
|
||||
if(BUILD_STATIC_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterLib)
|
||||
elseif(BUILD_SHARED_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterSharedLib)
|
||||
endif()
|
||||
include_directories(${EXENAME} ${CIMG_INCLUDE_DIR} )
|
||||
|
||||
# Installation
|
||||
if(LIB_INSTALL)
|
||||
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif(LIB_INSTALL)
|
||||
|
||||
#Installation of Qt DLLs on Windows
|
||||
jkqtplotter_deployqt(${EXENAME})
|
||||
|
||||
endif(CImg_FOUND)
|
127
examples/imageplot_cimg/README.md
Normal file
127
examples/imageplot_cimg/README.md
Normal file
@ -0,0 +1,127 @@
|
||||
# Example (JKQTPlotter): Simple math image plot, showin a 1-channel CImg image {#JKQTPlotterImagePlotCImg}
|
||||
This project (see `./examples/imageplot_cimg/`) simply creates a JKQTPlotter widget (as a new window) and adds a color-coded image plot of a mathematical function (here the Airy disk). The image is generated as an OpenCV `cv::Mat` (see https://opencv.org/) image and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore).
|
||||
To copy the data a special OpenCV Interface function `JKQTPCopyCvMatToColumn()` is used, that copies the data from a cv::Mat directly into a column.
|
||||
|
||||
The function `JKQTPCopyCvMatToColumn()` is available from the (non-default) header-only extension from `jkqtplotter/jkqtpinterfaceopencv.h`. This header provides facilities to interface JKQTPlotter with OpenCV. The OpenCV-binding itself is header-only, and NOT compiled into the JKQtPlotter libraries. Therefore you can simply include the header and use the facilities provided by it.
|
||||
|
||||
The CMake-build system of JKQtPlotter (and its examples) is compatible with both OpenCV 3.4.x and 4.x and uses the standard `find_package(OpenCV)` facilities provided by OpenCV to compile and bind against that library.
|
||||
If you want to build the OpenCV-based JKQtPlotter examples (see list above), you either have to ensure that CMake finds OpenCV by itself (i.e. somewhere in the default search paths), or you can set the CMake variable `OpenCV_DIR` so it points to the OpenCV directory before configuring JKQtPlotter.
|
||||
|
||||
|
||||
The source code of the main application is (see [`imageplot_cimg.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_cimg/imageplot_cimg.cpp):
|
||||
```.cpp
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimage.h"
|
||||
#include "jkqtplotter/jkqtpinterfaceopencv.h"
|
||||
#include <opencv/cv.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
JKQTPlotter plot;
|
||||
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
plot.getPlotter()->setUseAntiAliasingForGraphs(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForSystem(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForText(true); // nicer (but slower) text rendering
|
||||
JKQTPDatastore* ds=plot.getDatastore();
|
||||
|
||||
|
||||
// 2. now we create data for the charts (taken from https://commons.wikimedia.org/wiki/File:Energiemix_Deutschland.svg)
|
||||
cv::Mat airydisk(150, 150, CV_64FC1); // OpenCV-Image for the data
|
||||
const double dx=1e-2; // size of a pixel in x-direction [micrometers]
|
||||
const double dy=1e-2; // size of a pixel in x-direction [micrometers]
|
||||
const double w=static_cast<double>(airydisk.cols)*dx;
|
||||
const double h=static_cast<double>(airydisk.rows)*dy;
|
||||
|
||||
// 2.1 Parameters for airy disk plot (see https://en.wikipedia.org/wiki/Airy_disk)
|
||||
double NA=1.1; // numerical aperture of lens
|
||||
double wavelength=488e-3; // wavelength of the light [micrometers]
|
||||
|
||||
// 2.2 calculate image of airy disk in a row-major array
|
||||
double x, y=-h/2.0;
|
||||
for (int iy=0; iy<airydisk.rows; iy++ ) {
|
||||
x=-w/2.0;
|
||||
for (int ix=0; ix<airydisk.cols; ix++ ) {
|
||||
const double r=sqrt(x*x+y*y);
|
||||
const double v=2.0*M_PI*NA*r/wavelength;
|
||||
airydisk.at<double>(iy,ix) = pow(2.0*j1(v)/v, 2);
|
||||
x+=dx;
|
||||
}
|
||||
y+=dy;
|
||||
}
|
||||
|
||||
|
||||
// 3. make data available to JKQTPlotter by adding it to the internal datastore.
|
||||
// In this step the contents of one channel of the openCV cv::Mat is copied into a column
|
||||
// of the datastore in row-major order
|
||||
size_t cAiryDisk=JKQTPCopyCvMatToColumn(ds, airydisk, "imagedata");
|
||||
|
||||
|
||||
// 4. create a graph (JKQTPColumnMathImage) with the column created above as data
|
||||
// The data is color-coded with the color-palette JKQTPMathImageMATLAB
|
||||
// the converted range of data is determined automatically because setAutoImageRange(true)
|
||||
JKQTPColumnMathImage* graph=new JKQTPColumnMathImage(&plot);
|
||||
graph->setTitle("");
|
||||
// image column with the data
|
||||
graph->setImageColumn(cAiryDisk);
|
||||
// set size of the data (the datastore does not contain this info, as it only manages 1D columns of data and this is used to assume a row-major ordering
|
||||
graph->setNx(airydisk.cols);
|
||||
graph->setNy(airydisk.rows);
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->setX(-w/2.0);
|
||||
graph->setY(-h/2.0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->setWidth(w);
|
||||
graph->setHeight(h);
|
||||
// color-map is "MATLAB"
|
||||
graph->setPalette(JKQTPMathImageMATLAB);
|
||||
// get coordinate axis of color-bar and set its label
|
||||
graph->getColorBarRightAxis()->setAxisLabel("light intensity [A.U.]");
|
||||
// determine min/max of data automatically and use it to set the range of the color-scale
|
||||
graph->setAutoImageRange(true);
|
||||
// you can set the color-scale range manually by using:
|
||||
// graph->setAutoImageRange(false);
|
||||
// graph->setImageMin(0);
|
||||
// graph->setImageMax(10);
|
||||
|
||||
|
||||
// 5. add the graphs to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
|
||||
// 6. set axis labels
|
||||
plot.getXAxis()->setAxisLabel("x [{\\mu}m]");
|
||||
plot.getYAxis()->setAxisLabel("y [{\\mu}m]");
|
||||
|
||||
// 7. fix axis and plot aspect ratio to 1
|
||||
plot.getPlotter()->setMaintainAspectRatio(true);
|
||||
plot.getPlotter()->setMaintainAxisAspectRatio(true);
|
||||
|
||||
// 8 autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(600,600);
|
||||
plot.setWindowTitle("JKQTPColumnMathImage");
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
```
|
||||
The result looks like this:
|
||||
|
||||
![imageplot](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/imageplot_cimg.png)
|
||||
|
||||
See [`examples/imageplot`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot) for a detailed description of the other possibilities that the class JKQTPColumnMathImage (and also JKQTPMathImage) offer with respect to determining how an image is plottet.
|
||||
|
112
examples/imageplot_cimg/imageplot_cimg.cpp
Normal file
112
examples/imageplot_cimg/imageplot_cimg.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/** \example imageplot_cimg.cpp
|
||||
* Simple math image plot, showin a 1-channel CImg image
|
||||
*
|
||||
* \ref JKQTPlotterImagePlotCImg
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimage.h"
|
||||
#include "jkqtplotter/jkqtpinterfacecimg.h"
|
||||
#include "CImg.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
JKQTPlotter plot;
|
||||
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
plot.getPlotter()->setUseAntiAliasingForGraphs(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForSystem(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForText(true); // nicer (but slower) text rendering
|
||||
JKQTPDatastore* ds=plot.getDatastore();
|
||||
|
||||
|
||||
// 2. now we create data for the charts (taken from https://commons.wikimedia.org/wiki/File:Energiemix_Deutschland.svg)
|
||||
cimg_library::CImg<double> airydisk(150, 150); // CImg<T>-Image for the data
|
||||
const double dx=1e-2; // size of a pixel in x-direction [micrometers]
|
||||
const double dy=1e-2; // size of a pixel in x-direction [micrometers]
|
||||
const double w=static_cast<double>(airydisk.width())*dx;
|
||||
const double h=static_cast<double>(airydisk.height())*dy;
|
||||
|
||||
// 2.1 Parameters for airy disk plot (see https://en.wikipedia.org/wiki/Airy_disk)
|
||||
double NA=1.1; // numerical aperture of lens
|
||||
double wavelength=488e-3; // wavelength of the light [micrometers]
|
||||
|
||||
// 2.2 calculate image of airy disk in a row-major array
|
||||
double x, y=-h/2.0;
|
||||
for (int iy=0; iy<airydisk.height(); iy++ ) {
|
||||
x=-w/2.0;
|
||||
for (int ix=0; ix<airydisk.width(); ix++ ) {
|
||||
const double r=sqrt(x*x+y*y);
|
||||
const double v=2.0*M_PI*NA*r/wavelength;
|
||||
airydisk(iy,ix) = pow(2.0*j1(v)/v, 2);
|
||||
x+=dx;
|
||||
}
|
||||
y+=dy;
|
||||
}
|
||||
|
||||
|
||||
// 3. make data available to JKQTPlotter by adding it to the internal datastore.
|
||||
// In this step the contents of one channel of the CImg cimg_library::CImg<double> is copied into a column
|
||||
// of the datastore in row-major order
|
||||
size_t cAiryDisk=JKQTPCopyCImgToColumn(ds, airydisk, "imagedata");
|
||||
|
||||
|
||||
// 4. create a graph (JKQTPColumnMathImage) with the column created above as data
|
||||
// The data is color-coded with the color-palette JKQTPMathImageMATLAB
|
||||
// the converted range of data is determined automatically because setAutoImageRange(true)
|
||||
JKQTPColumnMathImage* graph=new JKQTPColumnMathImage(&plot);
|
||||
graph->setTitle("");
|
||||
// image column with the data
|
||||
graph->setImageColumn(cAiryDisk);
|
||||
// set size of the data (the datastore does not contain this info, as it only manages 1D columns of data and this is used to assume a row-major ordering
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->setX(-w/2.0);
|
||||
graph->setY(-h/2.0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->setWidth(w);
|
||||
graph->setHeight(h);
|
||||
// color-map is "MATLAB"
|
||||
graph->setPalette(JKQTPMathImageMATLAB);
|
||||
// get coordinate axis of color-bar and set its label
|
||||
graph->getColorBarRightAxis()->setAxisLabel("light intensity [A.U.]");
|
||||
// determine min/max of data automatically and use it to set the range of the color-scale
|
||||
graph->setAutoImageRange(true);
|
||||
// you can set the color-scale range manually by using:
|
||||
// graph->setAutoImageRange(false);
|
||||
// graph->setImageMin(0);
|
||||
// graph->setImageMax(10);
|
||||
|
||||
|
||||
// 5. add the graphs to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
|
||||
// 6. set axis labels
|
||||
plot.getXAxis()->setAxisLabel("x [{\\mu}m]");
|
||||
plot.getYAxis()->setAxisLabel("y [{\\mu}m]");
|
||||
|
||||
// 7. fix axis and plot aspect ratio to 1
|
||||
plot.getPlotter()->setMaintainAspectRatio(true);
|
||||
plot.getPlotter()->setMaintainAxisAspectRatio(true);
|
||||
|
||||
// 8 autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(600,600);
|
||||
plot.setWindowTitle("JKQTPColumnMathImage");
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
26
examples/imageplot_cimg/imageplot_cimg.pro
Normal file
26
examples/imageplot_cimg/imageplot_cimg.pro
Normal file
@ -0,0 +1,26 @@
|
||||
# source code for this simple demo
|
||||
SOURCES = imageplot_cimg.cpp
|
||||
|
||||
# configure Qt
|
||||
CONFIG += link_prl qt
|
||||
QT += core gui xml svg
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
# output executable name
|
||||
TARGET = imageplot_cimg
|
||||
|
||||
|
||||
|
||||
# Compile with CImg
|
||||
INCLUDEPATH += $$PWD/../../../CImg/include/
|
||||
INCLUDEPATH+=../../lib
|
||||
|
||||
CONFIG (debug, debug|release) {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/debug -ljkqtplotterlib_debug
|
||||
} else {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/release -ljkqtplotterlib
|
||||
}
|
||||
message("LIBS = $$LIBS")
|
||||
|
||||
win32-msvc*: DEFINES += _USE_MATH_DEFINES
|
||||
win32-msvc*: DEFINES += NOMINMAX
|
8
examples/imageplot_cimg/imageplot_cimg_and_lib.pro
Normal file
8
examples/imageplot_cimg/imageplot_cimg_and_lib.pro
Normal file
@ -0,0 +1,8 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += jkqtplotterlib imageplot_cimg
|
||||
|
||||
jkqtplotterlib.file = ../../qmake/staticlib/jkqtplotterlib/jkqtplotterlib.pro
|
||||
|
||||
imageplot_cimg.file=$$PWD/imageplot_cimg.pro
|
||||
imageplot_cimg.depends = jkqtplotterlib
|
@ -2,7 +2,7 @@
|
||||
This project (see `./examples/imageplot_opencv/`) simply creates a JKQTPlotter widget (as a new window) and adds a color-coded image plot of a mathematical function (here the Airy disk). The image is generated as an OpenCV `cv::Mat` (see https://opencv.org/) image and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore).
|
||||
To copy the data a special OpenCV Interface function `JKQTPCopyCvMatToColumn()` is used, that copies the data from a cv::Mat directly into a column.
|
||||
|
||||
The function `JKQTPCopyCvMatToColumn()` is available from the (non-default) header-only extension from `jkqtplotter/jkqtpopencvinterface.h`. This header provides facilities to interface JKQTPlotter with OpenCV. The OpenCV-binding itself is header-only, and NOT compiled into the JKQtPlotter libraries. Therefore you can simply include the header and use the facilities provided by it.
|
||||
The function `JKQTPCopyCvMatToColumn()` is available from the (non-default) header-only extension from `jkqtplotter/jkqtpinterfaceopencv.h`. This header provides facilities to interface JKQTPlotter with OpenCV. The OpenCV-binding itself is header-only, and NOT compiled into the JKQtPlotter libraries. Therefore you can simply include the header and use the facilities provided by it.
|
||||
|
||||
The CMake-build system of JKQtPlotter (and its examples) is compatible with both OpenCV 3.4.x and 4.x and uses the standard `find_package(OpenCV)` facilities provided by OpenCV to compile and bind against that library.
|
||||
If you want to build the OpenCV-based JKQtPlotter examples (see list above), you either have to ensure that CMake finds OpenCV by itself (i.e. somewhere in the default search paths), or you can set the CMake variable `OpenCV_DIR` so it points to the OpenCV directory before configuring JKQtPlotter.
|
||||
@ -14,7 +14,7 @@ The source code of the main application is (see [`imageplot_opencv.cpp`](https:/
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimage.h"
|
||||
#include "jkqtplotter/jkqtpopencvinterface.h"
|
||||
#include "jkqtplotter/jkqtpinterfaceopencv.h"
|
||||
#include <opencv/cv.h>
|
||||
|
||||
#ifndef M_PI
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimage.h"
|
||||
#include "jkqtplotter/jkqtpopencvinterface.h"
|
||||
#include "jkqtplotter/jkqtpinterfaceopencv.h"
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#ifndef M_PI
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Example (JKQTPlotter): Simple Math RGB/CMY Image Plot {#JKQTPlotterRGBImagePlot}
|
||||
This project (see `./examples/imageplot/`) simply creates a JKQTPlotter widget (as a new window) and adds an image plot of a mathematical function (here the Airy disk). The function is calculated with different parameters and then the result for each parameter is mapped onto a separate color channel in the output. The image is stored as a simple C-array in row-major ordering and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore). This very simple interface can also be used to interface with many common image processing libraries, like CImg or OpenCV.
|
||||
This project (see `./examples/rgbimageplot/`) simply creates a JKQTPlotter widget (as a new window) and adds an image plot of a mathematical function (here the Airy disk). The function is calculated with different parameters and then the result for each parameter is mapped onto a separate color channel in the output. The image is stored as a simple C-array in row-major ordering and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore). This very simple interface can also be used to interface with many common image processing libraries, like CImg or OpenCV.
|
||||
|
||||
The source code of the main application is (see [`rgbimageplot.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot/rgbimageplot.cpp):
|
||||
The source code of the main application is (see [`rgbimageplot.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot/rgbimageplot.cpp):
|
||||
```.cpp
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
|
1
examples/rgbimageplot_cimg/.gitignore
vendored
Normal file
1
examples/rgbimageplot_cimg/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/OpenCV-3.4.1
|
35
examples/rgbimageplot_cimg/CMakeLists.txt
Normal file
35
examples/rgbimageplot_cimg/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
find_package( CImg )
|
||||
if(CImg_FOUND)
|
||||
|
||||
set(EXAMPLE_NAME rgbimageplot_cimg)
|
||||
set(EXENAME jkqtptest_${EXAMPLE_NAME})
|
||||
|
||||
message( STATUS ".. Building Example ${EXAMPLE_NAME}" )
|
||||
|
||||
# Set up source files
|
||||
set(SOURCES ${EXAMPLE_NAME}.cpp)
|
||||
set(HEADERS )
|
||||
set(RESOURCES )
|
||||
set(UIS )
|
||||
|
||||
add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS})
|
||||
target_include_directories(${EXENAME} PRIVATE ../../lib)
|
||||
if(BUILD_STATIC_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterLib)
|
||||
elseif(BUILD_SHARED_LIBS)
|
||||
target_link_libraries(${EXENAME} JKQTPlotterSharedLib)
|
||||
endif()
|
||||
include_directories(${EXENAME} ${CIMG_INCLUDE_DIR} )
|
||||
|
||||
# Installation
|
||||
if(LIB_INSTALL)
|
||||
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif(LIB_INSTALL)
|
||||
|
||||
#Installation of Qt DLLs on Windows
|
||||
jkqtplotter_deployqt(${EXENAME})
|
||||
add_custom_command(TARGET ${EXENAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/rgbimageplot_cimg_example.bmp" $<TARGET_FILE_DIR:${EXENAME}>
|
||||
)
|
||||
endif(CImg_FOUND)
|
117
examples/rgbimageplot_cimg/README.md
Normal file
117
examples/rgbimageplot_cimg/README.md
Normal file
@ -0,0 +1,117 @@
|
||||
# Example (JKQTPlotter): Simple math image plot, showing a 3-channel CImg image {#JKQTPlotterImagePlotRGBCImg}
|
||||
This project (see `./examples/rgbimageplot_cimg/`) simply creates a JKQTPlotter widget (as a new window) and shows an RGB image read from a BMP-file. The image is generated as an [cimg](https://cimg.org/) [`cimg_library::CImg<uint8_t>`](http://cimg.eu/reference/structcimg__library_1_1CImg.html) image and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore).
|
||||
To copy the data a special cimg Interface function `JKQTPCopyCImgToColumn()` is used, that copies the data from a [CImg](https://cimg.eu/) [`cimg_library::CImg<uint8_t>`](http://cimg.eu/reference/structcimg__library_1_1CImg.html) directly into a column.
|
||||
|
||||
The function `JKQTPCopyCImgToColumn()` is available from the (non-default) header-only extension from `jkqtplotter/jkqtpinterfacecimg.h`. This header provides facilities to interface JKQTPlotter with cimg. The cimg-binding itself is header-only, and NOT compiled into the JKQtPlotter libraries. Therefore you can simply include the header and use the facilities provided by it.
|
||||
|
||||
The CMake-build system of JKQtPlotter (and its examples) is compatible with both cimg 3.4.x and 4.x and uses the standard `find_package(cimg)` facilities provided by cimg to compile and bind against that library.
|
||||
If you want to build the cimg-based JKQtPlotter examples (see list above), you either have to ensure that CMake finds cimg by itself (i.e. somewhere in the default search paths), or you can set the CMake variable `cimg_DIR` so it points to the cimg directory before configuring JKQtPlotter.
|
||||
|
||||
The source code of the main application is (see [`rgbimageplot_cimg.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_cimg/rgbimageplot_cimg.cpp):
|
||||
|
||||
```.cpp
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimagergb.h"
|
||||
#include "jkqtplotter/jkqtpinterfacecimg.h"
|
||||
#include "CImg.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
JKQTPlotter plot;
|
||||
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
plot.getPlotter()->setUseAntiAliasingForGraphs(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForSystem(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForText(true); // nicer (but slower) text rendering
|
||||
JKQTPDatastore* ds=plot.getDatastore();
|
||||
|
||||
|
||||
// 2. now we open a BMP-file and load it into an cimg cv::Mat
|
||||
cimg_library::CImg<uint8_t> picture; // CImg<T>-Image for the data
|
||||
picture.load_bmp("rgbimageplot_cimg_example.bmp");
|
||||
qDebug()<<picture.width()<<"x"<<picture.height()<<"x"<<picture.spectrum();
|
||||
|
||||
|
||||
|
||||
// 3. make data available to JKQTPlotter by adding it to the internal datastore.
|
||||
// In this step the contents of each channel of the cimg cv::Mat is copied into a column
|
||||
// of the datastore in row-major order
|
||||
size_t cPictureR=JKQTPCopyCImgToColumn(ds, picture, "R-channel", 0);
|
||||
size_t cPictureG=JKQTPCopyCImgToColumn(ds, picture, "G-channel", 1);
|
||||
size_t cPictureB=JKQTPCopyCImgToColumn(ds, picture, "B-channel", 2);
|
||||
|
||||
|
||||
// 4. create a graph (JKQTPColumnRGBMathImage) with the columns created above as data
|
||||
JKQTPColumnRGBMathImage* graph=new JKQTPColumnRGBMathImage(&plot);
|
||||
graph->setTitle("");
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->setX(0);
|
||||
graph->setY(0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->setWidth(picture.width());
|
||||
graph->setHeight(picture.height());
|
||||
// image column with the data
|
||||
graph->setImageRColumn(static_cast<int>(cPictureR));
|
||||
graph->setImageGColumn(static_cast<int>(cPictureG));
|
||||
graph->setImageBColumn(static_cast<int>(cPictureB));
|
||||
// determine min/max of each channel manually
|
||||
graph->setImageMinR(0);
|
||||
graph->setImageMaxR(255);
|
||||
graph->setImageMinG(0);
|
||||
graph->setImageMaxG(255);
|
||||
graph->setImageMinB(0);
|
||||
graph->setImageMaxB(255);
|
||||
|
||||
|
||||
|
||||
// 5. add the graphs to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
|
||||
// 6. set axis labels
|
||||
plot.getXAxis()->setAxisLabel("x [pixels]");
|
||||
plot.getYAxis()->setAxisLabel("y [pixels]");
|
||||
// 6.1 invert y-axis, so image is oriented correctly
|
||||
plot.getYAxis()->setInverted(true);
|
||||
|
||||
// 7. fix axis aspect ratio to width/height, so pixels are square
|
||||
plot.getPlotter()->setMaintainAspectRatio(true);
|
||||
plot.getPlotter()->setAspectRatio(double(picture.width())/double(picture.height()));
|
||||
|
||||
// 8. autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(800,600);
|
||||
plot.setWindowTitle("JKQTPColumnRGBMathImage");
|
||||
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The result looks like this:
|
||||
|
||||
![imageplot](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/rgbimageplot_cimg.png)
|
||||
|
||||
|
||||
|
||||
Note the step
|
||||
```.cpp
|
||||
// 5.1 invert y-axis, so image is oriented correctly
|
||||
plot.getYAxis()->setInverted(true);
|
||||
```
|
||||
above, which ensures that the image is not draw upside-down! This will reorient the y-axis to point from top to bottom (for increasing positive coordinates).
|
||||
The image would be upside-down, because computer images use a coordinate system with 0 at the top-left (left-handed coordinate system) and the JKQTPlotter has its 0 at the bottom-left (right-handed coordinate system).
|
||||
|
||||
|
||||
See [`examples/rgbimageplot`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot) for a detailed description of the other possibilities that the class JKQTPColumnRGBMathImage offer with respect to determining how an image is plotted.
|
||||
|
91
examples/rgbimageplot_cimg/rgbimageplot_cimg.cpp
Normal file
91
examples/rgbimageplot_cimg/rgbimageplot_cimg.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/** \example rgbimageplot_cimg.cpp
|
||||
* Simple math image plot, showin a 3-channel CImg image
|
||||
*
|
||||
* \ref JKQTPlotterImagePlotRGBCImg
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimagergb.h"
|
||||
#include "jkqtplotter/jkqtpinterfacecimg.h"
|
||||
#include "CImg.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
JKQTPlotter plot;
|
||||
|
||||
|
||||
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
||||
plot.getPlotter()->setUseAntiAliasingForGraphs(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForSystem(true); // nicer (but slower) plotting
|
||||
plot.getPlotter()->setUseAntiAliasingForText(true); // nicer (but slower) text rendering
|
||||
JKQTPDatastore* ds=plot.getDatastore();
|
||||
|
||||
|
||||
// 2. now we open a BMP-file and load it into an OpenCV cv::Mat
|
||||
cimg_library::CImg<uint8_t> picture; // CImg<T>-Image for the data
|
||||
picture.load_bmp("rgbimageplot_opencv_example.bmp");
|
||||
qDebug()<<picture.width()<<"x"<<picture.height()<<"x"<<picture.spectrum();
|
||||
|
||||
|
||||
|
||||
// 3. make data available to JKQTPlotter by adding it to the internal datastore.
|
||||
// In this step the contents of each channel of the openCV cv::Mat is copied into a column
|
||||
// of the datastore in row-major order
|
||||
size_t cPictureR=JKQTPCopyCImgToColumn(ds, picture, "R-channel", 0);
|
||||
size_t cPictureG=JKQTPCopyCImgToColumn(ds, picture, "G-channel", 1);
|
||||
size_t cPictureB=JKQTPCopyCImgToColumn(ds, picture, "B-channel", 2);
|
||||
|
||||
|
||||
// 4. create a graph (JKQTPColumnRGBMathImage) with the columns created above as data
|
||||
JKQTPColumnRGBMathImage* graph=new JKQTPColumnRGBMathImage(&plot);
|
||||
graph->setTitle("");
|
||||
// where does the image start in the plot, given in plot-axis-coordinates (bottom-left corner)
|
||||
graph->setX(0);
|
||||
graph->setY(0);
|
||||
// width and height of the image in plot-axis-coordinates
|
||||
graph->setWidth(picture.width());
|
||||
graph->setHeight(picture.height());
|
||||
// image column with the data
|
||||
graph->setImageRColumn(static_cast<int>(cPictureR));
|
||||
graph->setImageGColumn(static_cast<int>(cPictureG));
|
||||
graph->setImageBColumn(static_cast<int>(cPictureB));
|
||||
// determine min/max of each channel manually
|
||||
graph->setImageMinR(0);
|
||||
graph->setImageMaxR(255);
|
||||
graph->setImageMinG(0);
|
||||
graph->setImageMaxG(255);
|
||||
graph->setImageMinB(0);
|
||||
graph->setImageMaxB(255);
|
||||
|
||||
|
||||
|
||||
// 5. add the graphs to the plot, so it is actually displayed
|
||||
plot.addGraph(graph);
|
||||
|
||||
// 6. set axis labels
|
||||
plot.getXAxis()->setAxisLabel("x [pixels]");
|
||||
plot.getYAxis()->setAxisLabel("y [pixels]");
|
||||
// 6.1 invert y-axis, so image is oriented correctly
|
||||
plot.getYAxis()->setInverted(true);
|
||||
|
||||
// 7. fix axis aspect ratio to width/height, so pixels are square
|
||||
plot.getPlotter()->setMaintainAspectRatio(true);
|
||||
plot.getPlotter()->setAspectRatio(double(picture.width())/double(picture.height()));
|
||||
|
||||
// 8. autoscale the plot so the graph is contained
|
||||
plot.zoomToFit();
|
||||
|
||||
// show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(800,600);
|
||||
plot.setWindowTitle("JKQTPColumnRGBMathImage");
|
||||
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
26
examples/rgbimageplot_cimg/rgbimageplot_cimg.pro
Normal file
26
examples/rgbimageplot_cimg/rgbimageplot_cimg.pro
Normal file
@ -0,0 +1,26 @@
|
||||
# source code for this simple demo
|
||||
SOURCES = rgbimageplot_cimg.cpp
|
||||
|
||||
# configure Qt
|
||||
CONFIG += link_prl qt
|
||||
QT += core gui xml svg
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
# output executable name
|
||||
TARGET = rgbimageplot_cimg
|
||||
|
||||
|
||||
|
||||
# Compile with CImg
|
||||
INCLUDEPATH += $$PWD/../../../CImg/include/
|
||||
INCLUDEPATH+=../../lib
|
||||
|
||||
CONFIG (debug, debug|release) {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/debug -ljkqtplotterlib_debug
|
||||
} else {
|
||||
LIBS += -L../../qmake/staticlib/jkqtplotterlib/release -ljkqtplotterlib
|
||||
}
|
||||
message("LIBS = $$LIBS")
|
||||
|
||||
win32-msvc*: DEFINES += _USE_MATH_DEFINES
|
||||
win32-msvc*: DEFINES += NOMINMAX
|
8
examples/rgbimageplot_cimg/rgbimageplot_cimg_and_lib.pro
Normal file
8
examples/rgbimageplot_cimg/rgbimageplot_cimg_and_lib.pro
Normal file
@ -0,0 +1,8 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += jkqtplotterlib rgbimageplot_cimg
|
||||
|
||||
jkqtplotterlib.file = ../../qmake/staticlib/jkqtplotterlib/jkqtplotterlib.pro
|
||||
|
||||
rgbimageplot_cimg.file=$$PWD/rgbimageplot_cimg.pro
|
||||
rgbimageplot_cimg.depends = jkqtplotterlib
|
BIN
examples/rgbimageplot_cimg/rgbimageplot_cimg_example.bmp
Normal file
BIN
examples/rgbimageplot_cimg/rgbimageplot_cimg_example.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 412 KiB |
@ -1,19 +1,19 @@
|
||||
# Example (JKQTPlotter): Simple RGB image plot, showing a 3-channel OpenCV cv::Mat {#JKQTPlotterImagePlotRGBOpenCV}
|
||||
This project (see `./examples/imageplot_opencv/`) simply creates a JKQTPlotter widget (as a new window) and shows an RGB image read from a BMP-file. The image is generated as an [OpenCV](https://opencv.org/) [`cv::Mat`](https://docs.opencv.org/4.0.0/d3/d63/classcv_1_1Mat.html) image and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore).
|
||||
This project (see `./examples/rgbimageplot_opencv/`) simply creates a JKQTPlotter widget (as a new window) and shows an RGB image read from a BMP-file. The image is generated as an [OpenCV](https://opencv.org/) [`cv::Mat`](https://docs.opencv.org/4.0.0/d3/d63/classcv_1_1Mat.html) image and then copied into a single column of the internal datasdtore (JKQTPMathImage could be directly used without the internal datastore).
|
||||
To copy the data a special OpenCV Interface function `JKQTPCopyCvMatToColumn()` is used, that copies the data from a (https://opencv.org/) [`cv::Mat`](https://docs.opencv.org/4.0.0/d3/d63/classcv_1_1Mat.html) directly into a column.
|
||||
|
||||
The function `JKQTPCopyCvMatToColumn()` is available from the (non-default) header-only extension from `jkqtplotter/jkqtpopencvinterface.h`. This header provides facilities to interface JKQTPlotter with OpenCV.The OpenCV-binding itself is header-only, and NOT compiled into the JKQtPlotter libraries. Therefore you can simply include the header and use the facilities provided by it.
|
||||
The function `JKQTPCopyCvMatToColumn()` is available from the (non-default) header-only extension from `jkqtplotter/jkqtpinterfaceopencv.h`. This header provides facilities to interface JKQTPlotter with OpenCV.The OpenCV-binding itself is header-only, and NOT compiled into the JKQtPlotter libraries. Therefore you can simply include the header and use the facilities provided by it.
|
||||
|
||||
The CMake-build system of JKQtPlotter (and its examples) is compatible with both OpenCV 3.4.x and 4.x and uses the standard `find_package(OpenCV)` facilities provided by OpenCV to compile and bind against that library.
|
||||
If you want to build the OpenCV-based JKQtPlotter examples (see list above), you either have to ensure that CMake finds OpenCV by itself (i.e. somewhere in the default search paths), or you can set the CMake variable `OpenCV_DIR` so it points to the OpenCV directory before configuring JKQtPlotter.
|
||||
The CMake-build system of JKQtPlotter (and its examples) provides facilities to allow for `find_package(CImg)` to compile against that library.
|
||||
If you want to build the CImg-based JKQtPlotter examples (see list above), you either have to ensure that CMake finds CImg by itself (i.e. somewhere in the default search paths, e.g. `CMAKE_INSTALL_PREFIX`), or you can set the CMake variable `CImg_DIR` so it points to the directory of the `CImg.h` file, or before configuring JKQtPlotter.
|
||||
|
||||
The source code of the main application is (see [`imageplot_opencv.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/imageplot_opencv/imageplot_opencv.cpp):
|
||||
The source code of the main application is (see [`rgbimageplot_cimg.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot_opencv/rgbimageplot_cimg.cpp):
|
||||
```.cpp
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimage.h"
|
||||
#include "jkqtplotter/jkqtpopencvinterface.h"
|
||||
#include "jkqtplotter/jkqtpinterfaceopencv.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
|
||||
@ -111,4 +111,5 @@ This will reorient the y-axis to point from top to bottom (for increasing positi
|
||||
|
||||
|
||||
|
||||
See [`examples/rgbimageplot`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/rgbimageplot) for a detailed description of the other possibilities that the class JKQTPColumnRGBMathImage offer with respect to determining how an image is plotted.
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpimagergb.h"
|
||||
#include "jkqtplotter/jkqtpopencvinterface.h"
|
||||
#include "jkqtplotter/jkqtpinterfaceopencv.h"
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char* argv[])
|
||||
// show plotter and make it a decent size
|
||||
plot.show();
|
||||
plot.resize(800,600);
|
||||
plot.setWindowTitle("JKQTPColumnMathImage");
|
||||
plot.setWindowTitle("JKQTPColumnRGBMathImage");
|
||||
|
||||
|
||||
return app.exec();
|
||||
|
61
lib/jkqtplotter/jkqtpinterfacecimg.h
Normal file
61
lib/jkqtplotter/jkqtpinterfacecimg.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2018-2019 Jan W. Krieger (<jan@jkrieger.de>)
|
||||
|
||||
|
||||
|
||||
This software is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License (LGPL) as published by
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License (LGPL) for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License (LGPL)
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "jkqtplotter/jkqtpdatastorage.h"
|
||||
#include "CImg.h"
|
||||
|
||||
#ifndef JKQTPINTERFACECIMG_H
|
||||
#define JKQTPINTERFACECIMG_H
|
||||
|
||||
|
||||
/** \brief add one external column to the datastore. It will be filled with the contents of the CImg image \a img.
|
||||
* \ingroup jkqtpinterfacecimg
|
||||
*
|
||||
* \param datastore the datastore to which the <a href="https://cimg.eu/">CImg</a> matrix should be added (as column)
|
||||
* \param img <a href="http://cimg.eu/reference/structcimg__library_1_1CImg.html">cimg_library::CImg<T>-image</a> to store here
|
||||
* \param name name for the column
|
||||
* \param channel channel to copy from \a img
|
||||
* \param z z-plane to copy from \a img
|
||||
* \return the ID of the newly created column
|
||||
*
|
||||
* \see \ref jkqtpinterfacecimg, \ref JKQTPlotterImagePlotCImg or \ref JKQTPlotterImagePlotRGBCImg for details on how to use this function.
|
||||
*/
|
||||
template<class T>
|
||||
inline size_t JKQTPCopyCImgToColumn(JKQTPDatastore* datastore, const cimg_library::CImg<T>& img, const QString& name=QString(""), int channel=0, int z=0)
|
||||
{
|
||||
const size_t N=static_cast<size_t>(img.width()*img.height());
|
||||
double* d=static_cast<double*>(malloc(static_cast<size_t>(N)*sizeof(double)));
|
||||
|
||||
size_t r=0;
|
||||
for (int iy=0; iy<img.height(); iy++ ) {
|
||||
for (int ix=0; ix<img.width(); ix++ ) {
|
||||
d[r]=jkqtp_todouble(img.atXYZC(ix,iy,z,channel));
|
||||
r++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return datastore->addInternalImageColumn(d, img.width(), img.height(), name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // JKQTPINTERFACECIMG_H
|
@ -22,12 +22,12 @@
|
||||
#include "jkqtplotter/jkqtpdatastorage.h"
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#ifndef JKQTPOPENCVINTERFACE_H
|
||||
#define JKQTPOPENCVINTERFACE_H
|
||||
#ifndef JKQTPINTERFACEOPENCV_H
|
||||
#define JKQTPINTERFACEOPENCV_H
|
||||
|
||||
|
||||
/** \brief add one external column to the datastore. It will be filled with the contents of vector \a data.
|
||||
* \ingroup jkqtpopencvinterface
|
||||
/** \brief add one external column to the datastore. It will be filled with the contents of CImg matrix cv::Mat
|
||||
* \ingroup jkqtpinterfaceopencv
|
||||
*
|
||||
* \param datastore the datastore to which the <a href="https://opencv.org/">OpenCV</a> matrix shuld be added (as column)
|
||||
* \param mat <a href="https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html">OpenCV-matrix</a> to store here
|
||||
@ -35,7 +35,7 @@
|
||||
* \param channel to copy from \a mat
|
||||
* \return the ID of the newly created column
|
||||
*
|
||||
* \see \ref jkqtpopencvinterface, \ref JKQTPlotterImagePlotOpenCV or \ref JKQTPlotterImagePlotRGBOpenCV for details on how to use this function.
|
||||
* \see \ref jkqtpinterfaceopencv, \ref JKQTPlotterImagePlotOpenCV or \ref JKQTPlotterImagePlotRGBOpenCV for details on how to use this function.
|
||||
*/
|
||||
inline size_t JKQTPCopyCvMatToColumn(JKQTPDatastore* datastore, const cv::Mat& mat, const QString& name=QString(""), int channel=0);
|
||||
|
||||
@ -46,7 +46,7 @@ inline size_t JKQTPCopyCvMatToColumn(JKQTPDatastore* datastore, const cv::Mat& m
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
namespace JKQTPDatastore_Helper {
|
||||
/** \brief internal helper function for JKQTPCopyCvMatToColumn()
|
||||
* \ingroup jkqtpopencvinterface
|
||||
* \ingroup jkqtpinterfaceopencv
|
||||
* \internal */
|
||||
template <typename TPixel>
|
||||
inline void copyDataFromMat(double* data, const cv::Mat& mat, int channel) {
|
||||
@ -81,4 +81,4 @@ inline size_t JKQTPCopyCvMatToColumn(JKQTPDatastore* datastore, const cv::Mat& m
|
||||
|
||||
|
||||
|
||||
#endif // JKQTPOPENCVINTERFACE_H
|
||||
#endif // JKQTPINTERFACEOPENCV_H
|
BIN
screenshots/imageplot_cimg.png
Normal file
BIN
screenshots/imageplot_cimg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
screenshots/imageplot_cimg_small.png
Normal file
BIN
screenshots/imageplot_cimg_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
screenshots/rgbimageplot_cimg.png
Normal file
BIN
screenshots/rgbimageplot_cimg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 328 KiB |
BIN
screenshots/rgbimageplot_cimg_small.png
Normal file
BIN
screenshots/rgbimageplot_cimg_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
Loading…
Reference in New Issue
Block a user