CANDELbio / mantis-viewer

Electron-based multiplexed imaging viewer
Apache License 2.0
22 stars 7 forks source link

default scaling for low-count data #19

Closed ngreenwald closed 4 years ago

ngreenwald commented 4 years ago

When loading MIBI data, the default scaling is always much too low. This is fairly low priority, but it would be nice if the guess for a cap value worked better for data with very low (1-20) counts per pixel.

rj3d commented 4 years ago

I'm not sure what you mean by scaling in this context. Do you mean the default zoom, when large images are downsampled so they can fit in memory, the default brightness values, or something different?

If you mean the default brightness values, you can configure them to best suit your data by clicking on the preferences entry in the main menu.

ngreenwald commented 4 years ago

Hi Rob, yes, the default brightness is just what I was referring to. What would be nice is if mantis attempted to auto-scale the brightness for each channel independently, for example by setting the scaling to the max value of that channel in the image.

It also appears that it saves the settings if you've loaded an image set before, and sets those as the default. This is an awesome feature!!

rj3d commented 4 years ago

Awesome, I'm glad you like that it saves the settings from last time! If you're analyzing multiple image sets (a project) it will also copy any brightness adjustments you've made as you move from image set to image set.

Maybe I'm not understanding, but I think you can do what you just described in the preferences pane. If you go to the preferences pane, you can set the default min and max brightness as a percentage of channel's max value for each channel. So if you wanted no scaling for every channel, you can go through each channel and set the default brightness to 0% and 100%. Is that what you were thinking? If not, can you walk me through an example? Is there a heuristic that you're thinking would be useful for automatically picking how the brightness should be scaled?

ngreenwald commented 4 years ago

Sure thing. Could you explain what type of scaling is being done on the main page when we adjust the brightness?

Also, you said that "If you go to the preferences pane, you can set the default min and max brightness as a percentage of channel's max value." But then you said that no scaling would be setting the max to 100% of the max value, which actually does sound like scaling to me?

rj3d commented 4 years ago

Would be happy to explain! The brightness values on the sliders on the main page are taken from the selected marker and are the minimum and maximum pixel intensities for that marker. When you adjust the brightness Mantis does a linear transformation.

In TypeScript we generate m and b for the linear transformation by doing the following:

let b = curChannelSelectedMin === 0 ? 0 : curChannelSelectedMin / channelMaxIntensity
let m = curChannelSelectedMax === 0 ? 0 : channelMaxIntensity / (curChannelSelectedMax - curChannelSelectedMin)

We then apply these values to the image using a WebGL Uniform that looks like this:

gl_FragColor = min((gl_FragColor * m) + b, 1.0);

We do min with 1.0 here because WebGL only displays values between 0 and 1. When the image is first loaded, the pixel intensities are scaled to the range of 0 and 1 for the purposes of display.

So if you set the brightness values for a channel to 0% and 100%, the only scaling that should be going in is scaling to the range of 0 to 1 so that we can display the image. A display value of 1 will only correspond to the maximum pixel intensity for the selected marker.

ngreenwald commented 4 years ago

Got it, thanks! I didn't realize the data was already max-scaled 0-1. In that case, the settings tab for % max intensity as a default would definitely work for us.

I started playing around with it, and it appears that's its doing some calculations as you change this value. It lags a bit, and can't slide more than 10% per second; if I drag the slider faster than that, it lags out and then overshoots.

Thanks, Noah

On Wed, Feb 5, 2020 at 11:25 AM Robert Schiemann notifications@github.com wrote:

Would be happy to explain! The brightness values on the sliders on the main page are taken from the selected marker and are the minimum and maximum pixel intensities for that marker. When you adjust the brightness Mantis does a linear transformation.

In TypeScript we generate m and b for the linear transformation by doing the following:

let b = curChannelSelectedMin === 0 ? 0 : curChannelSelectedMin / channelMaxIntensity let m = curChannelSelectedMax === 0 ? 0 : channelMaxIntensity / (curChannelSelectedMax - curChannelSelectedMin)

We then apply these values to the image using a WebGL Uniform that looks like this:

gl_FragColor = min((gl_FragColor * m) + b, 1.0);

We do min with 1.0 here because WebGL only displays values between 0 and

  1. When the image is first loaded, the pixel intensities are scaled to the range of 0 and 1 for the purposes of display.

So if you set the brightness values for a channel to 0% and 100%, the only scaling that should be going in is scaling to the range of 0 to 1 so that we can display the image. A display value of 1 will only correspond to the maximum pixel intensity for the selected marker.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ParkerICI/mantis-viewer/issues/19?email_source=notifications&email_token=ADJB47JDBP2NR4AA6ODTFNDRBMHBTA5CNFSM4KP55ZTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK4VBOQ#issuecomment-582570170, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADJB47PUXZY5CVL2EHSEIDTRBMHBTANCNFSM4KP55ZTA .

rj3d commented 4 years ago

Awesome, I'm glad that the settings for default brightness works for you!

Yeah, we're aware of that lag. I hadn't thought of it in a bit, so thanks for the reminder! Those values get saved to a file on disk, and with the way things are currently written that happens every time the value changes. We have a ticket to fix that, but didn't get around to it for the 1.0 release. We should be getting to it for the 1.1, if not sooner!

Thanks again, Rob

On Wed, Feb 5, 2020, 10:04 AM ngreenwald notifications@github.com wrote:

Got it, thanks! I didn't realize the data was already max-scaled 0-1. In that case, the settings tab for % max intensity as a default would definitely work for us.

I started playing around with it, and it appears that's its doing some calculations as you change this value. It lags a bit, and can't slide more than 10% per second; if I drag the slider faster than that, it lags out and then overshoots.

Thanks, Noah

On Wed, Feb 5, 2020 at 11:25 AM Robert Schiemann <notifications@github.com

wrote:

Would be happy to explain! The brightness values on the sliders on the main page are taken from the selected marker and are the minimum and maximum pixel intensities for that marker. When you adjust the brightness Mantis does a linear transformation.

In TypeScript we generate m and b for the linear transformation by doing the following:

let b = curChannelSelectedMin === 0 ? 0 : curChannelSelectedMin / channelMaxIntensity let m = curChannelSelectedMax === 0 ? 0 : channelMaxIntensity / (curChannelSelectedMax - curChannelSelectedMin)

We then apply these values to the image using a WebGL Uniform that looks like this:

gl_FragColor = min((gl_FragColor * m) + b, 1.0);

We do min with 1.0 here because WebGL only displays values between 0 and

  1. When the image is first loaded, the pixel intensities are scaled to the range of 0 and 1 for the purposes of display.

So if you set the brightness values for a channel to 0% and 100%, the only scaling that should be going in is scaling to the range of 0 to 1 so that we can display the image. A display value of 1 will only correspond to the maximum pixel intensity for the selected marker.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/ParkerICI/mantis-viewer/issues/19?email_source=notifications&email_token=ADJB47JDBP2NR4AA6ODTFNDRBMHBTA5CNFSM4KP55ZTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK4VBOQ#issuecomment-582570170 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ADJB47PUXZY5CVL2EHSEIDTRBMHBTANCNFSM4KP55ZTA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ParkerICI/mantis-viewer/issues/19?email_source=notifications&email_token=AA7D37CM6BIYOXX46WLSO43RBMLVXA5CNFSM4KP55ZTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK4ZHUA#issuecomment-582587344, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7D37CPIV5WKHDBQUYFUW3RBMLVXANCNFSM4KP55ZTA .