我想模糊的圖像模糊的圖像。在這一點上,我可以模糊它沒有邊界。我讀過我可以通過將數據容器放入更大的數據容器來實現我的目標。我試過了,但是我不能成功地做到這一點。也許有人知道更簡單的解決方案來做到這一點這裏是我的代碼:用純C++
Image Blur::transform(const Image &inputImage)
{
Image input = (inputImage.type != ImageType::Grayscale)
? Grayscale().transform(inputImage)
: inputImage;
std::cout << "Blurring" << std::endl;
Image output = input;
auto indexAt = [&input](int row, int col) { return row * input.size.m_width + col; };
for (int row = m_BLUR_MASK_RADIUS; row < output.size.m_height - m_BLUR_MASK_RADIUS; row++)
{
for (int col = m_BLUR_MASK_RADIUS; col < output.size.m_width - m_BLUR_MASK_RADIUS; col++)
{
std::vector<uint8_t> pixel_values;
for (int row_offset = -m_BLUR_MASK_RADIUS; row_offset <= m_BLUR_MASK_RADIUS; row_offset++)
{
for (int col_offset = -m_BLUR_MASK_RADIUS; col_offset <= m_BLUR_MASK_RADIUS; col_offset++)
{
const int offset_pixel_index = indexAt(row + row_offset, col + col_offset);
pixel_values.push_back(input.data[offset_pixel_index]);
}
}
const int center_pixel_index = indexAt(row, col);
output.data[center_pixel_index] = getModifiedValue(pixel_values);
}
}
return output;
}
哪裏Image
是如下:
struct Image
{
std::vector<uint8_t> data;
Size size;
ImageType type;
int pixelCount() const {
return size.m_height * size.m_width;
}
Image() {}
Image(Size _size, ImageType _type) : size(_size), type(_type) {}
~Image() {}
};
struct Size
{
int m_width;
int m_height;
Size() {}
Size(int width, int height) : m_width(width), m_height(height) {}
};
enum class ImageType
{
Rgba,
Grayscale
};
所以你能幫忙嗎?
如果你嘗試過,你應該張貼,你寫了沒有工作的代碼。否則,唯一提及並不意味着太多。而且你不需要一個更大的容器來模糊圖像,邊緣檢查條件就可以做到。 –
@BartekBanachewicz上週試了一下。不幸的是,沒有該代碼已經 – gawron103