Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions CP5/active_plugins/DumpIt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import cellprofiler_core.module
from cellprofiler_core.setting.subscriber import ImageSubscriber
from cellprofiler_core.setting.text import ImageName
from cellprofiler_core.setting.text import Text
from cellprofiler_core.setting import Binary
from cellprofiler_core.setting import Color

__doc__ = """\
DumpIt
======

**DumpIt** does nothing of interest yet.


I am a module
look at me,
about as simple
as could be.

|

============ ============ ===============
Supports 2D? Supports 3D? Respects masks?
============ ============ ===============
YES NO YES
============ ============ ===============

"""

class DumpIt(cellprofiler_core.module.ImageProcessing):
module_name = "DumpIt"

variable_revision_number = 1

def create_settings(self):
self.x_name = ImageSubscriber(
"Select the input image", doc="Select the image you want to use."
)

self.y_name = ImageName(
"Name the output image",
self.__class__.__name__,
doc="Enter the name you want to call the image produced by this module.",
)
self.overlay_text = Text("Some Text", "Hello World!", doc="The text you would like to be overlayed on top of the image.")

self.binary = Binary("Some binary", True)
self.color = Color("Some color choice", "red")

def settings(self):
return [self.x_name, self.y_name, self.overlay_text, self.binary,
self.color]

def visible_settings(self):
return self.settings()

def run(self, workspace):
self.function = lambda x_data, args: ...
super().run(workspace)
78 changes: 78 additions & 0 deletions CP5/active_plugins/HelloWorld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import matplotlib.pyplot as plt
from matplotlib import patheffects
import numpy as np

import cellprofiler_core.module
import cellprofiler_core.setting.text

__doc__ = """\
HelloWorld
============

**HelloWorld** takes an image, and overlays "Hello World!" on top of it, by default.


I am a module
look at me,
about as simple
as could be.

|

============ ============ ===============
Supports 2D? Supports 3D? Respects masks?
============ ============ ===============
YES NO YES
============ ============ ===============

"""

class HelloWorld(cellprofiler_core.module.ImageProcessing):
module_name = "HelloWorld"

variable_revision_number = 1

def create_settings(self):
super().create_settings()
self.y_name.set_value("OverlayImage")
self.overlay_text = cellprofiler_core.setting.text.Text("Overlay Text", "Hello World!", doc="The text you would like to be overlayed on top of the image.")

def settings(self):
return super().settings() + [self.overlay_text]

# normally unnecessary, but ImageProcessing defines this so we have to too
def visible_settings(self):
return self.settings()

def run(self, workspace):
self.function = self.place_text_on_image
super().run(workspace)

def place_text_on_image(self,
img,
text,
x_pos = 0,
y_pos = 0.99,
color = "white",
weight = "bold",
ha = "left",
va = "top",
outline_color = "black",
outline_width = 3):
fig = plt.figure()
fig.figimage(img, resize=True)

fontsize = 34/400*img.shape[0]

# Main text
txt = fig.text(x_pos, y_pos, text, fontsize=fontsize, color=color, weight=weight,
horizontalalignment=ha, verticalalignment=va)

# Apply white outline using path_effects
outline_effect = patheffects.withStroke(linewidth=outline_width, foreground=outline_color)
txt.set_path_effects([outline_effect])

fig.canvas.draw()
annotated_img = np.asarray(fig.canvas.renderer.buffer_rgba())
plt.close(fig)
return annotated_img
83 changes: 83 additions & 0 deletions active_plugins/dumbmodule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#################################
#
# Imports from useful Python libraries
#
#################################

import locale
import sys

#################################
#
# Imports from CellProfiler
#
##################################

import cellprofiler_core.module
import cellprofiler_core.setting.text

__doc__ = """\
DumbModule
============

**DumbModule** does nothing of importance.


I am a module
look at me,
about as simple
as could be.

|

============ ============ ===============
Supports 2D? Supports 3D? Respects masks?
============ ============ ===============
NO NO NO
============ ============ ===============

"""

#raise NotImplementedError("DumbModule does nothing")

class DumbModule(cellprofiler_core.module.Module):
module_name = "DumbModule"
category = "Info"

variable_revision_number = 1

def create_settings(self):
self.some_setting = cellprofiler_core.setting.text.Text("dumb setting", "i am a setting", doc="I do nothing at all")

def settings(self):
return [self.some_setting]

def visible_settings(self):
return [self.some_setting]

def run(self, workspace):
f = open("/Users/ngogober/Desktop/log.txt", "wt")
f_repr = repr(f)
f.close()

labels = ["func name", "value"]
encoding_info_table = [
["locale.getdefaultlocale:", repr(locale.getdefaultlocale())],
["locale.getlocale", repr(locale.getlocale())],
["locale.getpreferredencoding (do not set)", repr(locale.getpreferredencoding(False))],
["locale.getpreferredencoding", repr(locale.getpreferredencoding())],
["sys.getfilesystemencoding", repr(sys.getfilesystemencoding())],
["filestream", f_repr],
]

if self.show_window:
workspace.display_data.statistics = encoding_info_table
workspace.display_data.labels = labels
else:
print(encoding_info_table)

def display(self, workspace, figure):
statistics = workspace.display_data.statistics
labels = workspace.display_data.labels
figure.set_subplots((1, 1))
figure.subplot_table(0, 0, statistics, labels)
Binary file added hackathon/HelloWorld.cpproj
Binary file not shown.
343 changes: 343 additions & 0 deletions hackathon/HelloWorld.ipynb

Large diffs are not rendered by default.