Skip to content

Commit

Permalink
fixed an issue with image display where image pixel size was not draw…
Browse files Browse the repository at this point in the history
…n correctly
  • Loading branch information
by408 committed Mar 14, 2024
1 parent 5518093 commit 89fd01b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions gui/polyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,11 @@ void polyView::imageToScreenRect(// inputs
utils::PositionedImage const& positioned_img,
QRect & screenRect) { // output

std::vector<int> x = {imageRect.left(), imageRect.right(),
imageRect.right(), imageRect.left()};
// Increase the right and bottom by 1 seems to work properly for Qt image display
std::vector<int> x = {imageRect.left(), imageRect.right()+1,
imageRect.right()+1, imageRect.left()};
std::vector<int> y = {imageRect.top(), imageRect.top(),
imageRect.bottom(), imageRect.bottom()};
imageRect.bottom()+1, imageRect.bottom()+1};

int big = std::numeric_limits<int>::max();
int min_ix = big, min_iy = big, max_ix = -big, max_iy = -big;
Expand Down
10 changes: 6 additions & 4 deletions gui/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,9 @@ bool utils::readImagePosition(std::string const& filename, std::vector<double> &
// Convert from world coordinates to this image's pixel coordinates.
void utils::worldToImage(double wx, double wy, utils::PositionedImage const& img, // inputs
double & ix, double & iy) { // outputs
ix = (wx - img.pos[0]) / img.pos[2];
iy = (wy - img.pos[1]) / img.pos[3];
// half grid shift for pixel center
ix = (wx - img.pos[0] + img.pos[2]/2) / img.pos[2];
iy = (wy - img.pos[1] + img.pos[3]/2) / img.pos[3];

// Flip in y
iy = img.qimg.height() - 1 - iy;
Expand All @@ -520,8 +521,9 @@ void utils::imageToWorld(double ix, double iy, utils::PositionedImage const& img
// Flip in y
iy = img.qimg.height() - 1 - iy;

wx = ix * img.pos[2] + img.pos[0];
wy = iy * img.pos[3] + img.pos[1];
// half grid shift for pixel center
wx = ix * img.pos[2] + img.pos[0] - img.pos[2]/2;
wy = iy * img.pos[3] + img.pos[1] - img.pos[3]/2;
}

// Find the box containing all polygons and images
Expand Down

0 comments on commit 89fd01b

Please sign in to comment.