30 requires std::is_arithmetic_v<T>
34 std::istringstream iss(file_path_image);
36 while (std::getline(iss, token,
'.')) {
46 init_image = ImageRead(
58 width_height_ = {init_image.
Width(), init_image.
Height()};
59 pixels_ = std::make_unique<T[]>(TotalPixels());
63 std::ranges::transform(
67 [](
const unsigned char i) -> T {return (T)i;});
71 requires std::is_arithmetic_v<T>
79 std::getline(file, doc);
89 requires std::is_arithmetic_v<T>
91 const std::string& file_name,
93 bool weighted_rgb_conversion)
const
98 std::ifstream file(file_name, std::ios::in | std::ios::binary);
101 std::cout <<
"ERROR READING FILE P5: " << file_name << std::endl;
103 unsigned int cols, rows;
105 cols = std::stoul(buf);
107 rows = std::stoul(buf);
110 if (std::stoul(buf) > UCHAR_MAX)
111 std::cout <<
"ERROR READING FILE UCHAR MAX: " << file_name << std::endl;
117 file.read((
char*) (out_image.PointerToPixelsStart()),
118 (cols * rows *
sizeof(
char)));
121 std::unique_ptr<char[]> rgb_image_ptr =
122 std::make_unique<char[]>(3 * cols * rows);
125 file.read(rgb_image_ptr.get(), 3 * cols * rows *
sizeof(
char));
131 for (
unsigned int i = 0; i < (rows * cols); i++) {
132 float r_channel_weight = 1.0f / 3.0f;
133 float b_channel_weight = 1.0f / 3.0f;
134 float g_channel_weight = 1.0f / 3.0f;
135 if (weighted_rgb_conversion) {
136 r_channel_weight = 0.299f;
137 b_channel_weight = 0.587f;
138 g_channel_weight = 0.114f;
140 out_image.PointerToPixelsStart()[i] =
141 (
unsigned char)std::floor(
142 r_channel_weight * ((
float) rgb_image_ptr[i * 3]) +
143 g_channel_weight * ((
float) rgb_image_ptr[i * 3 + 1]) +
144 b_channel_weight * ((
float) rgb_image_ptr[i * 3 + 2]) +
Declares class to define images that are used in bp processing.
Class to define images that are used in bp processing.
unsigned int Height() const
unsigned int Width() const
void LoadImageAsGrayScale(const std::string &file_path_image)
void pnm_read(std::ifstream &file, std::string &buf) const
T * PointerToPixelsStart() const
BpImage< unsigned char > ImageRead(const std::string &file_name, beliefprop::ImageType image_type, bool weighted_rgb_conversion=true) const
constexpr std::string_view kPGMExt
constexpr bool kUseWeightedRGBToGrayscaleConversion
constexpr std::string_view kPPMExt