ericmandel / js9

astronomical image display everywhere
https://js9.si.edu
Other
121 stars 50 forks source link

Fits Image Display Area + Rotation #79

Closed jllamas closed 3 years ago

jllamas commented 3 years ago

Hello,

We are using JS9 to display some FITs images, but we want to view them rotated. When I rotate the image the display area doesn't change.

Here are a couple of screen shots, where the image is loaded normally, its very tall. When you zoom out it shows the image using the full height.

Screen Shot 2021-06-28 at 4 18 01 PM Screen Shot 2021-06-28 at 4 18 07 PM

When we rotate the image, and zoom out, you can see its still constrained by width, I'd expect it to use the full width.

Screen Shot 2021-06-28 at 4 18 20 PM Screen Shot 2021-06-28 at 4 18 24 PM

It could be an issue with the way we are rotating the image? We tried adding a default rotate options into the js9prefs.js file, but it never seemed to actually rotate the image. I ended up using a rotation function with a set timeout waiting for the JS9.GetLoadStatus() == "complete".

Cheers, Jake

ericmandel commented 3 years ago

@jllamas Are you using the Montage RotateDats() reprojection call or the cheaper SetRotate() call? And can I get a copy of the FITS file, so that I don't have to dummy up the data? I suspect I didn't work hard enough at changing the dimensions of the image ...

jllamas commented 3 years ago

Hey Eric,

You can use the same FITs from my other ticket https://caltech.box.com/s/8t1hbyvsztu1w5l9nvig25kmer74qrjt

We are using JS9.SetRotate() ala:

function rotateFits() {
  if (JS9.GetLoadStatus() == "complete") {
    JS9.SetRotate(-90);
  } else {
    setTimeout(rotateFits, 300);
  }
}
ericmandel commented 3 years ago

@jllamas Ah, thanks, I should have remembered that I have one of your FITS files already. I'll look at this tomorrow.

ericmandel commented 3 years ago

@jllamas This problem is fixed and updated in Github. I tightly limit the pixels for which RGB colors are calculated (for speed) and this limit needed to be extended in cases where non-square images were rotated and displayed in non-square displays, as in your case. I also fixed a typo that caused the panner to go awry in this case.

Because rotation first sets up a transformation maxtrix that gets applied to the display canvas and then redisplays the image, it's tricky to support rotate:90 in the opts object at Load time. In javascript you can just use the onload function:

          JS9.Load(file, {onload: (im) => {
          JS9.SetRotate(90, {display: im});
      }});

Let me know if you have problems ...

jllamas commented 3 years ago

Hello Eric,

We've deployed the new code (I ended up downloading 3.6 from the website as opposed to github) and it works great!

Loads like this:

Screen Shot 2021-08-02 at 3 40 22 PM

Clicking zoom (-) shows more! Great!

Screen Shot 2021-08-02 at 3 40 26 PM

However clicking the last zoom button, which I would expect to fill the screen to the max boundary. JS9 zoom it even further (-), instead of filling the width.

Screen Shot 2021-08-02 at 3 40 29 PM

Please let us know if that last item is a bug or expected, otherwise we can close this issue.

Thank you very much! Jacob

ericmandel commented 3 years ago

@jllamas Hi Jacob, it looks right to me, in the sense that going to zoom 1/16 causes the pixels to be resampled by another factor of two, and therefore the image size is reduced by 2 in both width and height. You can see this easily with the Panner plugin ... btw, have you tried zoom to fit? Does that give you the full display you want?

That said, I do wonder what you are expecting ... there may be a nuance I'm missing here.

jllamas commented 3 years ago

@ericmandel yeah in the last image above I clicked the 'zoom to fit', and compared to where I was in the middle picture it zoomed out further.

I opened a local fits file, and clicked 'zoom to fit' and it did as expected, filling the view port to the first maximum boundry. The dynamically loaded and rotated image 'zoom to fit', as guess, seems to be using the width before the rotation where its tall and skinny?

ericmandel commented 3 years ago

@jllamas Ah, right, zoomToFit was not taking the rotation into account at all. I have this working on my development machine, but I want to have a look at the panner plugin before I update, there is something not quite right there as well ...

ericmandel commented 3 years ago

@jllamas OK, I believe I have fixed this issue and also fixed some related problems with the panner plugin. It's all updated in GitHub, so "git pull" will get the latest, assuming you cloned.

jllamas commented 3 years ago

I've updated JS9 in our app, and everything works as expected. Thank you!