chimcla.stage_2a_bar_selection¶
Important
Historically grown and messy module for bar selection (or “separation”)
contains:
class
CavityCarrierImageAnalyzer(“FormenTrägerBildAnalyzer”)class
ExtendedSqliteDict
Module Contents¶
Classes¶
Special layer on top of numpy arrays which accept custom attributes |
|
HistogramEvaluation for one complete (81-cell) image |
Functions¶
decorator for parallelization |
|
Identify a linear trend in vertical direction and compensate it. |
|
problem: The list of bounding boxes is not sorted. it has to be calculated in which row an col every bb is. Also after this function the bbox_list is sorted (starting with 1st row) |
|
Iterate through a list of (extended) bounding boxes |
|
Support for angle detection of a bar: find out which columns are relevant to test |
|
:param dc: debug container |
|
:param delta: offset in pixels which will be ignored at each border |
|
For a given cell image return the indices of columns, that are the border of the chocolate bar |
|
Convert a path into a |
|
Data¶
API¶
- chimcla.stage_2a_bar_selection.REPO_ROOT¶
‘join(…)’
- chimcla.stage_2a_bar_selection.DATA_DIR¶
‘join(…)’
- chimcla.stage_2a_bar_selection.BBOX_EXPECTED_WITH¶
26
- chimcla.stage_2a_bar_selection.BBOX_EXPECTED_HEIGHT¶
104
- chimcla.stage_2a_bar_selection.BBOX_TOL¶
6
- chimcla.stage_2a_bar_selection.PREPROCESS_BORDERS¶
False
- chimcla.stage_2a_bar_selection.BBOX_MIN_WITH¶
23
- chimcla.stage_2a_bar_selection.CRIT_PIX_THRESHOLD¶
5
- chimcla.stage_2a_bar_selection.vv¶
None
- chimcla.stage_2a_bar_selection.CELL_KEY_END¶
None
- chimcla.stage_2a_bar_selection.cell_keys¶
None
- chimcla.stage_2a_bar_selection.uk¶
None
- class chimcla.stage_2a_bar_selection.ExtendedSqliteDict(filename=None, tablename='unnamed', flag='c', autocommit=False, journal_mode='DELETE', encode=encode, decode=decode, encode_key=identity, decode_key=identity, timeout=5, outer_stack=True)[source]¶
Bases:
sqlitedict.SqliteDict- put_container(main_key, cont, key_list, commit=False)[source]¶
convenience function to write selected content of a container to the database
- VALID_FLAGS¶
[‘c’, ‘r’, ‘w’, ‘n’]
- _new_conn()¶
- __enter__()¶
- __exit__(*exc_info)¶
- __str__()¶
- __repr__()¶
- __len__()¶
- __bool__()¶
- iterkeys()¶
- itervalues()¶
- iteritems()¶
- keys()¶
- values()¶
- items()¶
- __contains__(key)¶
- __getitem__(key)¶
- __setitem__(key, value)¶
- __delitem__(key)¶
- update(items=(), **kwds)¶
- __iter__()¶
- clear()¶
- static get_tablenames(filename)¶
- commit(blocking=True)¶
- sync¶
None
- close(do_log=True, force=False)¶
- terminate()¶
- __del__()¶
- get(key, default=None)¶
- __or__(other)¶
- __ror__(other)¶
- __ior__(other)¶
- __copy__()¶
- copy()¶
- classmethod fromkeys(iterable, value=None)¶
- __slots__¶
()
- __marker¶
‘object(…)’
- pop(key, default=__marker)¶
- popitem()¶
- setdefault(key, default=None)¶
- __abc_tpflags__¶
None
- __eq__(other)¶
- __reversed__¶
None
- classmethod __subclasshook__(C)¶
- __class_getitem__¶
‘classmethod(…)’
- chimcla.stage_2a_bar_selection.db¶
‘ExtendedSqliteDict(…)’
- chimcla.stage_2a_bar_selection.mpl_draw_rect(x, y, w, h, ax=None, linewidth=1, edgecolor='r', facecolor='none')[source]¶
- chimcla.stage_2a_bar_selection.put_text(image, origin, text, fontScale=0.35, color=(255, 0, 0), thickness=1)[source]¶
- chimcla.stage_2a_bar_selection.vertical_detrend(img, y_start, y_end, dc=None)[source]¶
Identify a linear trend in vertical direction and compensate it.
Intended to be used for bbox detection only
:param X1: specify region of interest :param X2: specify region of interest :param Y1: specify region of interest :param Y2: specify region of interest :param y_start: start of trend detection :param y_end: end of trend detection
- chimcla.stage_2a_bar_selection.get_bbox_list_robust(img, expected_number, plot=False, return_all=False, dc=None)[source]¶
- chimcla.stage_2a_bar_selection.get_bbox_list(img, plot=False, return_all=False, thresh=75, dc=None)[source]¶
- chimcla.stage_2a_bar_selection.assign_row_col(bbox_list)[source]¶
problem: The list of bounding boxes is not sorted. it has to be calculated in which row an col every bb is. Also after this function the bbox_list is sorted (starting with 1st row)
- chimcla.stage_2a_bar_selection.find_missing_boxes(bbox_list)[source]¶
Iterate through a list of (extended) bounding boxes
- chimcla.stage_2a_bar_selection.img_bbox_cache¶
None
- chimcla.stage_2a_bar_selection.colors¶
[‘#1f77b4’, ‘#ff7f0e’, ‘#2ca02c’, ‘#d62728’, ‘#9467bd’, ‘#8c564b’, ‘#e377c2’, ‘#7f7f7f’, ‘#bcbd22’, …
- class chimcla.stage_2a_bar_selection.Attr_Array(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)[source]¶
Bases:
numpy.ndarraySpecial layer on top of numpy arrays which accept custom attributes
Initialization
- __abs__()¶
- __add__(value)¶
- __and__(value)¶
- __array__(dtype=None)¶
- __array_wrap__(obj)¶
- __contains__(key)¶
- __copy__()¶
- __deepcopy__(memo)¶
- __divmod__(value)¶
- __eq__(value)¶
- __float__()¶
- __floordiv__()¶
- __ge__(value)¶
- __getitem__(key)¶
- __gt__(value)¶
- __iadd__(value)¶
- __iand__(value)¶
- __ifloordiv__(value)¶
- __ilshift__(value)¶
- __imod__(value)¶
- __imul__(value)¶
- __int__()¶
- __invert__()¶
- __ior__(value)¶
- __ipow__(value)¶
- __irshift__(value)¶
- __isub__(value)¶
- __itruediv__(value)¶
- __ixor__(value)¶
- __le__(value)¶
- __len__()¶
- __lshift__(value)¶
- __lt__(value)¶
- __matmul__(value)¶
- __mod__(value)¶
- __mul__(value)¶
- __ne__(value)¶
- __neg__()¶
- __or__(value)¶
- __pos__()¶
- __pow__()¶
- __repr__()¶
- __rshift__()¶
- __setitem__(key, value)¶
- __str__()¶
- __sub__(value)¶
- __truediv__(value)¶
- __xor__(value)¶
- all(axis=None, out=None, keepdims=False)¶
- any(axis=None, out=None, keepdims=False)¶
- argmax(axis=None, out=None)¶
- argmin(axis=None, out=None)¶
- argpartition(kth, axis=-1, kind='introselect', order=None)¶
- argsort(axis=-1, kind='quicksort', order=None)¶
- astype(dtype, order='K', casting='unsafe', subok=True, copy=True)¶
- byteswap(inplace=False)¶
- choose(choices, out=None, mode='raise')¶
- clip(min=None, max=None, out=None)¶
- compress(condition, axis=None, out=None)¶
- conj()¶
- conjugate()¶
- copy(order='C')¶
- cumprod(axis=None, dtype=None, out=None)¶
- cumsum(axis=None, dtype=None, out=None)¶
- diagonal(offset=0, axis1=0, axis2=1)¶
- dot(b, out=None)¶
- dump(file)¶
- dumps()¶
- fill(value)¶
- flatten(order='C')¶
- getfield(dtype, offset=0)¶
- item(*args)¶
- itemset(*args)¶
- max(axis=None, out=None)¶
- mean(axis=None, dtype=None, out=None, keepdims=False)¶
- min(axis=None, out=None, keepdims=False)¶
- newbyteorder(new_order='S')¶
- nonzero()¶
- partition(kth, axis=-1, kind='introselect', order=None)¶
- prod(axis=None, dtype=None, out=None, keepdims=False)¶
- ptp(axis=None, out=None)¶
- put(indices, values, mode='raise')¶
- ravel(order='C')¶
- repeat(repeats, axis=None)¶
- reshape(shape, order='C')¶
- resize(new_shape, refcheck=True)¶
- round(decimals=0, out=None)¶
- searchsorted(v, side='left', sorter=None)¶
- setfield(val, dtype, offset=0)¶
- setflags(write=None, align=None, uic=None)¶
- sort(axis=-1, kind='quicksort', order=None)¶
- squeeze(axis=None)¶
- std(axis=None, dtype=None, out=None, ddof=0, keepdims=False)¶
- sum(axis=None, dtype=None, out=None, keepdims=False)¶
- swapaxes(axis1, axis2)¶
- take(indices, axis=None, out=None, mode='raise')¶
- tobytes(order='C')¶
- tofile(fid, sep='', format='%s')¶
- tolist()¶
- tostring(order='C')¶
- trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)¶
- transpose(*axes)¶
- var(axis=None, dtype=None, out=None, ddof=0, keepdims=False)¶
- view(dtype=None, type=None)¶
- classmethod __class_getitem__(value)¶
- chimcla.stage_2a_bar_selection.BAR_THRESHOLD¶
110
- chimcla.stage_2a_bar_selection.get_test_column_idcs(img, plot=False)[source]¶
Support for angle detection of a bar: find out which columns are relevant to test
- exception chimcla.stage_2a_bar_selection.InconsistentAngle[source]¶
Bases:
ValueError- class __cause__¶
- class __context__¶
- __delattr__()¶
- __dir__()¶
- __eq__()¶
- __format__()¶
- __ge__()¶
- __getattribute__()¶
- __getstate__()¶
- __gt__()¶
- __hash__()¶
- __le__()¶
- __lt__()¶
- __ne__()¶
- __new__()¶
- __reduce__()¶
- __reduce_ex__()¶
- __repr__()¶
- __setattr__()¶
- __setstate__()¶
- __sizeof__()¶
- __str__()¶
- __subclasshook__()¶
- class __suppress_context__¶
- class __traceback__¶
- add_note()¶
- class args¶
- with_traceback()¶
- exception chimcla.stage_2a_bar_selection.MissingBoundingBoxes[source]¶
Bases:
ValueError- class __cause__¶
- class __context__¶
- __delattr__()¶
- __dir__()¶
- __eq__()¶
- __format__()¶
- __ge__()¶
- __getattribute__()¶
- __getstate__()¶
- __gt__()¶
- __hash__()¶
- __le__()¶
- __lt__()¶
- __ne__()¶
- __new__()¶
- __reduce__()¶
- __reduce_ex__()¶
- __repr__()¶
- __setattr__()¶
- __setstate__()¶
- __sizeof__()¶
- __str__()¶
- __subclasshook__()¶
- class __suppress_context__¶
- class __traceback__¶
- add_note()¶
- class args¶
- with_traceback()¶
- chimcla.stage_2a_bar_selection.get_symlog_hist(img_fpath, hr_row, hr_col, delta=None, return_cell=False, dc=None, ccia=None)[source]¶
:param dc: debug container
- chimcla.stage_2a_bar_selection.get_symlog_hist_from_cell(cell, delta=None, dc=None)[source]¶
:param delta: offset in pixels which will be ignored at each border
- chimcla.stage_2a_bar_selection.adapt_rotation_and_margin(bbox, img, forced_angle=None, plot=True)[source]¶
- class chimcla.stage_2a_bar_selection.CavityCarrierImageAnalyzer(img_fpath, bboxes=True)[source]¶
Initialization
- BBOX_EXPECTED_WITH¶
26
- BBOX_EXPECTED_HEIGHT¶
104
- BBOX_EXPECTED_DX¶
7
- BBOX_EXPECTED_DY¶
51
- BBOX_ROWS¶
3
- BBOX_COLS¶
27
- BBOX_NUMBER¶
None
- ROI_DX¶
5
- ROI_DY¶
5
- THRESHOLDS¶
[75, 70, 80, 65, 85]
- detrend_upper_row()[source]¶
Identify a linear trend in the upper row and compensate it.
Intended to be used for bbox detection only
- find_cell_corners(hr_row, hr_col, plot=False, dc=None)[source]¶
return absolute coordinates of the upper left corner of a cell
- estimate_angle_for_cell(hr_row, hr_col, e=3, f=3, dc=None)[source]¶
Use angle analyzer if possible. Evaluate image otherwise
- chimcla.stage_2a_bar_selection.CavityCarrierImageAnalyzier¶
None
- class chimcla.stage_2a_bar_selection.AngleAnalyzer[source]¶
Initialization
- get_angle_offset_for_img(ccia: chimcla.stage_2a_bar_selection.CavityCarrierImageAnalyzer)[source]¶
- chimcla.stage_2a_bar_selection.aa¶
‘AngleAnalyzer(…)’
- chimcla.stage_2a_bar_selection.get_border_columns(cell_img, dark_value_thresh=100, dark_share_thresh=0.7, dc=None)[source]¶
For a given cell image return the indices of columns, that are the border of the chocolate bar
- chimcla.stage_2a_bar_selection.pfname¶
‘namedtuple(…)’
- chimcla.stage_2a_bar_selection.analyze_img_fpath(fpath) chimcla.stage_2a_bar_selection.pfname[source]¶
Convert a path into a
pfname-object (with attributes like.date,.time, …)
- chimcla.stage_2a_bar_selection.get_original_image_fpath(img_fpath, cropped=True, resized=True) str[source]¶
- class chimcla.stage_2a_bar_selection.HistEvaluation(img_fpath: str, suffix: str = '', ev_crit_pix=False, training_data_flag=False, history_eval_flag=False)[source]¶
HistogramEvaluation for one complete (81-cell) image
Initialization
:param ev_crit_pix: bool; default False; evaluate critical pixels if true additional information about the critical pixels is collected and stored :param training_data_flag: bool; save plots also for non-critical cells + store plots for raw cell images
- hist_dict_path¶
‘join(…)’
- total_res_fpath¶
None
- CS_LIMIT¶
40
- get_criticality_summary(save_to_db=False)[source]¶
iterate over self.criticality_container_cache and return cumulated values
- get_criticality_score(cell_hist, cell, q, ev_crit_pix=None, dc=None)[source]¶
for a given histogram and lower and upper bounds, calculate a score which reflects how critical a given histogram is
:param q: quantile container (with attributes q.lower, …)
- get_critical_pixel_info(cell_hist, cell, q_curve, dc=None)[source]¶
:param q_curve: one of the histogram-quantile curves (e.g. q_upper, q_med, q_lower)
- abstractmethod find_critical_cells_for_hist_dict(hist_dict, img_fpath, exclude_cell_keys=None, training_data_flag=False)[source]¶
- evaluate_cell(cell_key, dc=None, save_options=None, force_plot=False, recalc_hist=False)[source]¶
returns 0 for an uncritical cell, 1 for a critical cell Also saves an evaluation plot for every critical cell
- save_cell_for_experimental_img(cell_key, cell_hist, q, cc, save_options)[source]¶
:param cc: criticality_container
- false_positive_correction(false_positive_dir)[source]¶
This iterates over false positives and adapts the affected histograms such that they are not recognized as anomaly anymore.
- save_and_plot_critical_cell(img_fpath, hr_row, hr_col, cell_hist, q, cc, save_options)[source]¶
:param cc: criticality_container :param q: quantile container
- _plot_cell_analysis_image__paper(cell_data: ipydex.Container)[source]¶
This version of the method is adapted for the needs of the paper