Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support color histogram equalization #1203

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 66 additions & 24 deletions corelib/src/CameraThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/core/IMUFilter.h"
#include "rtabmap/core/Features2d.h"
#include "rtabmap/core/clams/discrete_depth_distortion_model.h"
#include <opencv2/imgproc/types_c.h>
#include <opencv2/stitching/detail/exposure_compensate.hpp>
#include <rtabmap/utilite/UTimer.h>
#include <rtabmap/utilite/ULogger.h>
Expand Down Expand Up @@ -543,46 +544,87 @@ void CameraThread::postUpdate(SensorData * dataPtr, CameraInfo * info) const

if(_histogramMethod && !data.imageRaw().empty())
{
if(data.imageRaw().type() == CV_8UC1)
UDEBUG("");
UTimer timer;
cv::Mat image;
if(_histogramMethod == 1)
{
UDEBUG("");
UTimer timer;
cv::Mat image;
if(_histogramMethod == 1)
if(data.imageRaw().type() == CV_8UC1)
{
cv::equalizeHist(data.imageRaw(), image);
if(!data.depthRaw().empty())
}
else if(data.imageRaw().type() == CV_8UC3)
{
cv::Mat channels[3];
cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb);
cv::split(image, channels);
cv::equalizeHist(channels[0], channels[0]);
cv::merge(channels, 3, image);
cv::cvtColor(image, image, CV_YCrCb2BGR);
}
if(!data.depthRaw().empty())
{
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
}
else if(!data.rightRaw().empty())
{
cv::Mat right;
if(data.rightRaw().type() == CV_8UC1)
{
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
cv::equalizeHist(data.rightRaw(), right);
}
else if(!data.rightRaw().empty())
else if(data.rightRaw().type() == CV_8UC3)
{
cv::Mat right;
cv::equalizeHist(data.rightRaw(), right);
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
cv::Mat channels[3];
cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb);
cv::split(right, channels);
cv::equalizeHist(channels[0], channels[0]);
cv::merge(channels, 3, right);
cv::cvtColor(right, right, CV_YCrCb2BGR);
}
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
}
else if(_histogramMethod == 2)
}
else if(_histogramMethod == 2)
{
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(3.0);
if(data.imageRaw().type() == CV_8UC1)
{
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(3.0);
clahe->apply(data.imageRaw(), image);
if(!data.depthRaw().empty())
}
else if(data.imageRaw().type() == CV_8UC3)
{
cv::Mat channels[3];
cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb);
cv::split(image, channels);
clahe->apply(channels[0], channels[0]);
cv::merge(channels, 3, image);
cv::cvtColor(image, image, CV_YCrCb2BGR);
}
if(!data.depthRaw().empty())
{
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
}
else if(!data.rightRaw().empty())
{
cv::Mat right;
if(data.rightRaw().type() == CV_8UC1)
{
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
clahe->apply(data.rightRaw(), right);
}
else if(!data.rightRaw().empty())
else if(data.rightRaw().type() == CV_8UC3)
{
cv::Mat right;
clahe->apply(data.rightRaw(), right);
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
cv::Mat channels[3];
cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb);
cv::split(right, channels);
clahe->apply(channels[0], channels[0]);
cv::merge(channels, 3, right);
cv::cvtColor(right, right, CV_YCrCb2BGR);
}
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
}
if(info) info->timeHistogramEqualization = timer.ticks();
}
else
{
UWARN("Histogram equalization only supports grayscale images...");
}
if(info) info->timeHistogramEqualization = timer.ticks();
}

if(_stereoExposureCompensation && !data.imageRaw().empty() && !data.rightRaw().empty())
Expand Down