Skip to content

Commit

Permalink
fixed bug in code
Browse files Browse the repository at this point in the history
  • Loading branch information
avdmitry committed Dec 20, 2014
1 parent a424d88 commit b6102d2
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,27 +329,37 @@ void ImageDisplayer::DisplayImage(float* data, int num_images, int image_id) {
void ImageDisplayer::CreateImage(const float* data, int num_images, int image_id, Mat &image) {
int num_colors_width = (int)sqrt(num_colors_);
int num_colors_height = (num_colors_ + num_colors_width - 1) / num_colors_width;
int display_width = show_separate_ ? width_ * num_colors_width: width_;
int display_height = show_separate_ ? height_ * num_colors_height: height_;
int display_colors_type = show_separate_ ? CV_8UC1 : CV_8UC3;
int display_width = show_separate_ ? width_ * num_colors_width : width_;
int display_height = show_separate_ ? height_ * num_colors_height : height_;
int display_colors_type = show_separate_ ? CV_32FC1 : CV_32FC3;

image.create(display_width, display_height, display_colors_type);
for (int k=0; k<num_colors_; k++) {
for (int k=0; k<num_colors_; k++)
{
int off_color = 0;
if (3==num_colors_)
{
off_color += 2-k;
}
for (int i=0; i<height_; ++i)
{
char *im = image.ptr<char>(i);
int off_width = 0;
int off_height = 0;
if (show_separate_)
{
off_width = (k % num_colors_width) * width_;
off_height = (k / num_colors_width) * height_;
}
float *im = image.ptr<float>(i + off_height);

for (int j=0; j<width_; ++j)
{
char val = (char)255*data[image_id + num_images * (j + width_ * (i + k * height_))];
if (show_separate_) {
im = image.ptr<char>(i + (k / num_colors_width) * height_);
im[3*(j + (k % num_colors_width) * width_)+(2 )] = val;
} else {
im[3*(j )+(2-k)] = val;
}
float val = data[image_id + num_images * (j + width_ * (i + k * height_))];
im[num_colors_*(j + off_width) + off_color] = val;
}
}
}
normalize(image, image, 0, 1, NORM_MINMAX);
}

void ImageDisplayer::YUVToRGB(const float* yuv, float* rgb, int spacing) {
Expand Down Expand Up @@ -391,22 +401,22 @@ void ImageDisplayer::DisplayWeights(float* data, int size, int num_filters, int
}
}

image.create(size * num_filters_w, size * num_filters_h, CV_8UC3);
image.create(size * num_filters_w, size * num_filters_h, CV_32FC3);
for (int f = 0; f < num_filters; f++) {
for (int k = 0; k < 3; k++) {
for (int h = 0; h < size; h++) {
for (int w = 0; w < size; w++) {

data_pos = f + num_filters * (w + size * (h + size * k));
col = w + size * (f % num_filters_w);
row = h + size * (f / num_filters_w);

char *im = image.ptr<char>(row);
im[3*col+(2-k)] = (char)255*data[data_pos];
float *im = image.ptr<float>(row);
im[3*col+(2-k)] = data[data_pos];
}
}
}
}
normalize(image, image, 0, 1, NORM_MINMAX);

const Scalar color(0, 0, 0);
resizeOCV(image, display_size, display_size);
Expand Down

0 comments on commit b6102d2

Please sign in to comment.