Skip to content

Commit

Permalink
self referencing with reference input
Browse files Browse the repository at this point in the history
  • Loading branch information
ngergihun committed Oct 1, 2024
1 parent 8fb6b53 commit bf4d520
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
13 changes: 11 additions & 2 deletions orangecontrib/snom/widgets/owpreprocessimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import Orange.data
from Orange import preprocess
from Orange.widgets.widget import Output
from Orange.widgets.widget import Output, Input

from orangecontrib.spectroscopy.widgets.owhyper import BasicImagePlot

Expand Down Expand Up @@ -131,8 +131,17 @@ def progress_interrupt(i: float):
state.set_partial_result((n, data, None))
return orig_data, data

class SpectralImagePreprocessReference(SpectralImagePreprocess, openclass=True):
class Inputs(SpectralImagePreprocess.Inputs):
reference = Input("Reference", Orange.data.Table)

@Inputs.reference
def set_reference(self, reference):
self.reference_data = reference


class OWPreprocessImage(SpectralImagePreprocessReference):

class OWPreprocessImage(SpectralImagePreprocess):
name = "Preprocess image"
id = "orangecontrib.snom.widgets.preprocessimage"
description = "Process image"
Expand Down
1 change: 1 addition & 0 deletions orangecontrib/snom/widgets/preprocessors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from orangecontrib.snom.widgets.preprocessors import phase_rotation # noqa: F401
from orangecontrib.snom.widgets.preprocessors import simple_normalize # noqa: F401
from orangecontrib.snom.widgets.preprocessors import linelevel # noqa: F401
from orangecontrib.snom.widgets.preprocessors import self_reference # noqa: F401
70 changes: 70 additions & 0 deletions orangecontrib/snom/widgets/preprocessors/self_reference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from AnyQt.QtWidgets import QFormLayout, QLabel

from orangecontrib.spectroscopy.widgets.preprocessors.utils import BaseEditorOrange, REFERENCE_DATA_PARAM
from orangecontrib.spectroscopy.widgets.gui import lineEditIntRange

from pySNOM.images import SelfReference

from orangecontrib.snom.preprocess.utils import (
PreprocessImageOpts2DOnlyWhole,
)
from orangecontrib.snom.widgets.preprocessors.registry import preprocess_image_editors
import numpy as np

class SelfRef(PreprocessImageOpts2DOnlyWhole):
def __init__(self, reference):
self.reference = reference.X

def transform_image(self, image):
ref = (np.reshape(self.reference,np.shape(image)))
d = SelfReference(referencedata=ref).transform(
image
)
return d


class SelfRefEditor(BaseEditorOrange):
name = "Self-referencing"
qualname = "orangecontrib.snom.self_reference"

def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)

self.reference = None

form = QFormLayout()
self.reference_info = QLabel("Reference data from input!")
form.addRow(self.reference_info)
self.controlArea.setLayout(form)

def activateOptions(self):
pass # actions when user starts changing options

def setParameters(self, params):
self.update_reference_info()

def set_reference_data(self, reference):
self.reference = reference
self.update_reference_info()

def update_reference_info(self):
if not self.reference:
self.reference_info.setText("Reference: missing!")
self.reference_info.setStyleSheet("color: red")
else:
rinfo = "Reference order: N"
self.reference_info.setText(rinfo)
self.reference_info.setStyleSheet("color: black")

@classmethod
def createinstance(cls, params):
params = dict(params)
reference = params.get(REFERENCE_DATA_PARAM, None)
return SelfRef(reference=reference)

def set_preview_data(self, data):
if data:
pass # TODO any settings


preprocess_image_editors.register(SelfRefEditor, 400)

0 comments on commit bf4d520

Please sign in to comment.