void GrayFilterWidget::applyFilter(InputArray in, OutputArray out) const { // check weather the filter can be applied if (!(checkInput(in).first)) { return; } // the filter can be applied // split the cannels of the input image auto channels = splitChannels(in.at(0).get()); // create a zero image cv::Mat tmp = cv::Mat::zeros(in.at(0).get().rows, in.at(0).get().cols, in.at(0).get().depth()); // multiply all channels with their factor and add it to tmp // if there are factors for more channels than the input image has, this // channels // will be ignored for (std::size_t i = 0; ((i < channels.size()) && (i < chanValues_.size())); i++) { // multiply each channel with its factor and add the result to // tmp tmp += channels.at(i) * (chanValues_.at(i)->value()); } // finally assign tmp to out out.at(0).get() = tmp; }
std::pair<bool, QString> ChangedPixelsWidget::checkInput(InputArray in) const { if (in.at(0).get().size() != in.at(1).get().size()) { return std::make_pair(false, "images need to have same size"); } size_t inChannels = in.at(0).get().channels(); if (inChannels != static_cast<size_t>(in.at(1).get().channels())) { return std::make_pair( false, "images need to have same number of channels"); } if (inChannels>10 || inChannels<1) { return std::make_pair( false, "images need to have 1 up to 10 channels"); } int i0depth=in.at(0).get().depth(); if (i0depth!=in.at(1).get().depth()) { return std::make_pair( false, "images need to have the same depth"); } if (!((i0depth==CV_8U)||(i0depth==CV_8S)||(i0depth==CV_16U)||(i0depth==CV_16S)|| (i0depth==CV_32S)||(i0depth==CV_32F)||(i0depth==CV_64F))) { return std::make_pair(false, "images have unknown depth"); } return std::make_pair(true, ""); }