-
Notifications
You must be signed in to change notification settings - Fork 16
Complete cell-SAM with two channel selection #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mimithecoconut
wants to merge
20
commits into
vanvalenlab:main
Choose a base branch
from
mimithecoconut:cellSAMfinal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
72c3292
disabled cells opacity for cell types
mimithecoconut d9b7f8f
fix lint with pre-commit
mimithecoconut 0cb96c6
added segment all button and mask rendering
mimithecoconut 494953b
requirement file change back
mimithecoconut 9c56182
requirement file change back
mimithecoconut a96fda3
try fix backend test
mimithecoconut c0670ae
fix backend test 2
mimithecoconut c9018d2
backend test fix3
mimithecoconut 8a07688
added server side connection to SAM
mimithecoconut b876772
added frontend to backend of two channel selections
mimithecoconut 5ba2060
two channel selection function on cellSAM
mimithecoconut 29962d0
Fix windows line endings.
rossbar 9f1196a
Revert comments in blueprint.py
rossbar 8b8c9ae
Undo more purely cosmetic changes to clean up diff.
rossbar 123199b
Revert unintended changes/additions.
rossbar 45bcf2d
Revert more unintended changes.
rossbar 40f2ab8
Rm hardcoded IP - use env setup instead.
rossbar 9ed40a1
final clean up
mimithecoconut 8673c41
Undo unnecessary requirements pinning.
rossbar 5fefbb8
Add configuration values for cellsam server.
rossbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,7 @@ venv/ | |
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
| deepcell-env/ | ||
|
|
||
| # Spyder project settings | ||
| .spyderproject | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import asyncio | ||
| import pickle | ||
| import zlib | ||
|
|
||
| import websockets | ||
| from flask import current_app | ||
|
|
||
| from deepcell_label.config import CELLSAM_IP, CELLSAM_PORT | ||
|
|
||
|
|
||
| # connects to cell SAM server | ||
| async def perform_send(to_send): | ||
| uri = f'ws://{CELLSAM_IP}:{CELLSAM_PORT}' | ||
|
|
||
| async with websockets.connect(uri, ping_interval=None) as websocket: | ||
| data = {'img': to_send} | ||
| pkt = zlib.compress(pickle.dumps(data)) | ||
| await websocket.send(pkt) | ||
|
|
||
| pkt_received = await websocket.recv() | ||
|
|
||
| mask = pickle.loads(zlib.decompress(pkt_received)) | ||
| return mask | ||
|
|
||
|
|
||
| def send_to_server(to_send): | ||
| current_app.logger.info('Sent to server to generate mask for cellSAM') | ||
| mask = asyncio.run(perform_send(to_send)) | ||
| return mask |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
frontend/src/Project/EditControls/SegmentSamControls/ActionButtons.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { useSelector } from '@xstate/react'; | ||
| import { FormLabel } from '@mui/material'; | ||
| import Box from '@mui/material/Box'; | ||
| import ButtonGroup from '@mui/material/ButtonGroup'; | ||
| import SegmentAllButton from './ActionButtons/SegmentAllButton'; | ||
| import { useRaw } from '../../ProjectContext'; | ||
|
|
||
| function ActionButtons() { | ||
| const raw = useRaw(); | ||
| const layers = useSelector(raw, (state) => state.context.layers); | ||
| const layer = layers[0]; | ||
| return ( | ||
| <Box display='flex' flexDirection='column'> | ||
| <FormLabel>Actions</FormLabel> | ||
| <ButtonGroup orientation='vertical'> | ||
| <SegmentAllButton layer={layer} /> | ||
| </ButtonGroup> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| export default ActionButtons; |
36 changes: 36 additions & 0 deletions
36
frontend/src/Project/EditControls/SegmentSamControls/ActionButtons/ActionButton.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import Button from '@mui/material/Button'; | ||
| import Tooltip from '@mui/material/Tooltip'; | ||
| import { bind } from 'mousetrap'; | ||
| import React, { useEffect } from 'react'; | ||
|
|
||
| // for adding tooltip to disabled buttons | ||
| // from https://stackoverflow.com/questions/61115913 | ||
|
|
||
| const ActionButton = ({ tooltipText, disabled, onClick, hotkey, ...other }) => { | ||
| const adjustedButtonProps = { | ||
| disabled: disabled, | ||
| component: disabled ? 'div' : undefined, | ||
| onClick: disabled ? undefined : onClick, | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| bind(hotkey, onClick); | ||
| }, [hotkey, onClick]); | ||
|
|
||
| return ( | ||
| <Tooltip title={tooltipText} placement='right'> | ||
| <Button | ||
| {...other} | ||
| {...adjustedButtonProps} | ||
| sx={{ | ||
| p: 0, | ||
| '&.Mui-disabled': { | ||
| pointerEvents: 'auto', | ||
| }, | ||
| }} | ||
| /> | ||
| </Tooltip> | ||
| ); | ||
| }; | ||
|
|
||
| export default ActionButton; |
92 changes: 92 additions & 0 deletions
92
frontend/src/Project/EditControls/SegmentSamControls/ActionButtons/SegmentAllButton.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { useSelector } from '@xstate/react'; | ||
| import React, { useCallback } from 'react'; | ||
| import { useEditSegment, useSelect, useRaw } from '../../../ProjectContext'; | ||
| import ActionButton from './ActionButton'; | ||
| import { MenuItem, TextField } from '@mui/material'; | ||
| import Grid from '@mui/material/Grid'; | ||
|
|
||
| function LayerSelector({ layer, channelType }) { | ||
| const segment = useEditSegment(); | ||
| const nuclearChannel = useSelector(segment, (state) => state.context.nuclearChannel); | ||
| const wholeCellChannel = useSelector(segment, (state) => state.context.wholeCellChannel); | ||
|
|
||
| const raw = useRaw(); | ||
| const names = useSelector(raw, (state) => state.context.channelNames); | ||
|
|
||
| const onChangeNuclear = (e) => { | ||
| segment.send({ type: 'SET_NUCLEAR_CHANNEL', nuclearChannel: Number(e.target.value) }); | ||
| }; | ||
|
|
||
| const onChangeWholeCell = (e) => { | ||
| segment.send({ type: 'SET_WHOLE_CELL_CHANNEL', wholeCellChannel: Number(e.target.value) }); | ||
| }; | ||
|
|
||
| return channelType == 'nuclear' ? ( | ||
| <TextField | ||
| select | ||
| size='small' | ||
| value={nuclearChannel} | ||
| onChange={onChangeNuclear} | ||
| sx={{ width: 130 }} | ||
| > | ||
| {names.map((opt, index) => ( | ||
| <MenuItem key={index} value={index}> | ||
| {opt} | ||
| </MenuItem> | ||
| ))} | ||
| </TextField> | ||
| ) : ( | ||
| <TextField | ||
| select | ||
| size='small' | ||
| value={wholeCellChannel} | ||
| onChange={onChangeWholeCell} | ||
| sx={{ width: 130 }} | ||
| > | ||
| {names.map((opt, index) => ( | ||
| <MenuItem key={index} value={index}> | ||
| {opt} | ||
| </MenuItem> | ||
| ))} | ||
| </TextField> | ||
| ); | ||
| } | ||
|
|
||
| function SegmentAllButton({ props, layer }) { | ||
| const segment = useEditSegment(); | ||
| const grayscale = useSelector(segment, (state) => state.matches('display.grayscale')); | ||
|
|
||
| const onClick = useCallback(() => segment.send('SEGMENTALL'), [segment]); | ||
|
|
||
| const tooltipText = ( | ||
| <span> | ||
| Generate all the segmentation masks <kbd>M</kbd> | ||
| </span> | ||
| ); | ||
|
|
||
| return ( | ||
| <Grid> | ||
| Select Nuclear Channel | ||
| <Grid item xs={10.5}> | ||
| <LayerSelector layer={layer} channelType={'nuclear'} /> | ||
| </Grid> | ||
| Select Whole Cell Channel | ||
| <Grid item xs={10.5}> | ||
| <LayerSelector layer={layer} channelType={'wholeCell'} /> | ||
| </Grid> | ||
| <Grid> | ||
| <ActionButton | ||
| {...props} | ||
| // disabled={!grayscale} | ||
| tooltipText={grayscale ? tooltipText : 'Run cell sam on one channel'} | ||
| onClick={onClick} | ||
| hotkey='m' | ||
| > | ||
| Segment All | ||
| </ActionButton> | ||
| </Grid> | ||
| </Grid> | ||
| ); | ||
| } | ||
|
|
||
| export default SegmentAllButton; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rdilip for now, let's record the commit hash of the cellsam compute server that works with this version of deepcell-label. In principle we can use tags as well, which may make more sense once the formatting of messages etc. is completely decided.
The most elegant way to do this would be to include the cellsam server as a submodule in this repo; however, mixing public and private repos in this way is likely to cause problems (I don't even know if/how it's supported). Nevertheless, something to keep in mind if the cellsam code is released in the future.