<commit_before>#pragma once

#ifndef INCLUDE_OCVG_DARKLIGHT
#define INCLUDE_OCVG_DARKLIGHT

#include "..\stdafx.h"

using namespace cv;
using namespace cuda;
using namespace std;

namespace openCVGraph
{
    // Brightfield / Darkfield correction
    // Corrected = (Image - Darkfield) / (Brightfield - Darkfield) * 2**16 (for 16 bit data)

    class BrightDarkFieldCorrection : public Filter
    {
    public:

        static void BrightDarkFieldCorrection::SliderCallback(int pos, void * userData) {
            BrightDarkFieldCorrection* filter = (BrightDarkFieldCorrection *)userData;
            filter->FieldToView(pos);
        }

        BrightDarkFieldCorrection::BrightDarkFieldCorrection(std::string name, GraphData& graphData,
            int width = 512, int height = 512)
            : Filter(name, graphData, width, height)
        {

        }

        bool BrightDarkFieldCorrection::init(GraphData& graphData) override
        {
            Filter::init(graphData);

            graphData.m_NeedCV_16UC1 = true;
            // Need 8 bit if we're viewing it
            if (m_showView) {
                graphData.m_NeedCV_8UC1 = true;
            }

            // get the Bright Dark images from file

            Mat img = imread(m_BrightFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imBrightFieldGpu16U.upload(img);
            }
            else {
                assert(false);
            }

            img = imread(m_DarkFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imDarkFieldGpu16U.upload(img);
            }
            else {
                assert(false);
            }

            // Bright - Dark as 32F
            cuda::subtract(m_imBrightFieldGpu16U, m_imDarkFieldGpu16U, m_imTemp16UGpu);
            m_imTemp16UGpu.convertTo(m_imBrightMinusDarkFieldGpu32F, CV_32F);

            if (m_showView) {
                // To write on the overlay, you must allocate it.
                // This indicates to the renderer the need to merge it with the final output image.
                // m_imViewTextOverlay = Mat(m_width, m_height, CV_8U);

                if (m_showSlider) {
                    createTrackbar("BrightDarkFieldCorrection", m_CombinedName, &m_FieldToView, 4, SliderCallback, this);
                }
            }

            return true;
        }

        ProcessResult BrightDarkFieldCorrection::process(GraphData& graphData) override
        {
            if (graphData.m_UseCuda) {
                // sub darkfield
                cuda::subtract(graphData.m_imCapGpu16UC1, m_imDarkFieldGpu16U, m_imTemp16UGpu);<commit_msg>Logging BrightDarkfield<commit_after>#pragma once

#ifndef INCLUDE_OCVG_DARKLIGHT
#define INCLUDE_OCVG_DARKLIGHT

#include "..\stdafx.h"

using namespace cv;
using namespace cuda;
using namespace std;

namespace openCVGraph
{
    // Brightfield / Darkfield correction
    // Corrected = (Image - Darkfield) / (Brightfield - Darkfield) * 2**16 (for 16 bit data)

    class BrightDarkFieldCorrection : public Filter
    {
    public:

        static void BrightDarkFieldCorrection::SliderCallback(int pos, void * userData) {
            BrightDarkFieldCorrection* filter = (BrightDarkFieldCorrection *)userData;
            filter->FieldToView(pos);
        }

        BrightDarkFieldCorrection::BrightDarkFieldCorrection(std::string name, GraphData& graphData,
            int width = 512, int height = 512)
            : Filter(name, graphData, width, height)
        {

        }

        bool BrightDarkFieldCorrection::init(GraphData& graphData) override
        {
            Filter::init(graphData);

            graphData.m_NeedCV_16UC1 = true;
            // Need 8 bit if we're viewing it
            if (m_showView) {
                graphData.m_NeedCV_8UC1 = true;
            }

            // get the Bright Dark images from file

            Mat img = imread(m_BrightFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imBrightFieldGpu16U.upload(img);
            }
            else {
                graphData.m_Logger->error ("Unable to load BrightField: " + m_BrightFieldPath);
                return false;
            }

            img = imread(m_DarkFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imDarkFieldGpu16U.upload(img);
            }
            else {
                graphData.m_Logger->error("Unable to load DarkField: " + m_DarkFieldPath);
                return false;
            }

            // Bright - Dark as 32F
            cuda::subtract(m_imBrightFieldGpu16U, m_imDarkFieldGpu16U, m_imTemp16UGpu);
            m_imTemp16UGpu.convertTo(m_imBrightMinusDarkFieldGpu32F, CV_32F);

            if (m_showView) {
                // To write on the overlay, you must allocate it.
                // This indicates to the renderer the need to merge it with the final output image.
                // m_imViewTextOverlay = Mat(m_width, m_height, CV_8U);

                if (m_showSlider) {
                    createTrackbar("BrightDarkFieldCorrection", m_CombinedName, &m_FieldToView, 4, SliderCallback, this);
                }
            }

            return true;
        }

        ProcessResult BrightDarkFieldCorrection::process(GraphData& graphData) override
        {
            if (graphData.m_UseCuda) {
                // sub darkfield
                cuda::subtract(graphData.m_imCapGpu16UC1, m_imDarkFieldGpu16U, m_imTemp16UGpu);
{'fraction_non_alphanumeric': 0.08118212568987004, 'fraction_numerical': 0.015666726010325798, 'mean_word_length': 1.993074054342035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5436113', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1631, 'n_words': 345}