scikit-surgerybk

Logo

GitHub Actions CI statuss Test coverage Documentation Status https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg Follow scikit_surgery on twitter

Author: Thomas Dowrick

scikit-surgerybk is a Python library for interfacing with BK ultrasound machines, and is part of the SciKit-Surgery software project, developed at the Wellcome EPSRC Centre for Interventional and Surgical Sciences, part of University College London (UCL).

scikit-surgerybk supports Python 2.7 and Python 3.6/3.7/3.8.

Developing

Cloning

You can clone the repository using the following command:

git clone https://github.com/SciKit-Surgery/scikit-surgerybk

Running tests

Pytest is used for running unit tests:

pip install pytest
python -m pytest

Linting

This code conforms to the PEP8 standard. Pylint can be used to analyse the code:

pip install pylint
pylint --rcfile=tests/pylintrc sksurgerybk

Installing

You can pip install directly from the repository as follows:

pip install git+https://github.com/SciKit-Surgery/scikit-surgerybk

Contributing

Please see the contributing guidelines.

Acknowledgements

Supported by Wellcome and EPSRC.

Requirements for scikit-surgerybk

This is the software requirements file for scikit-surgerybk, part of the SNAPPY project. The requirements listed below should define what scikit-surgerybk does. Each requirement can be matched to a unit test that checks whether the requirement is met.

Requirements

ID Description Test
0000 Module has a help page pylint, see tests/pylint.rc and tox.ini
0001 Functions are documented pylint, see tests/pylint.rc and tox.ini
0002 Package has a version number No test yet, handled by git.

latest

sksurgerybk package

Subpackages
sksurgerybk.interface package
Submodules
sksurgerybk.interface.bk5000 module

This module sets the connection to the BK scanner

class sksurgerybk.interface.bk5000.BK5000(timeout, frames_per_second)[source]

Bases: object

This class sets the TCP connection with the BK scanner

clear_bytes_in_buffer(start, end)[source]

Clear a set of bytes in bytearray buffer

Parameters:
  • start (integer) – Start index
  • end (integer) – End integer
connect_to_host(address, port)[source]

Connects the client to the host/serverself.

Implements a try/except block to catch potential errors.

Parameters: address(string): the IP address port(integer): the port

decode_image()[source]

Process the stream of data received from the BK5000 and convert it into a numpy array which represents the ultrasound image.

Control bytes are 1, 4 and 27. Flipped control bytes (1s complement of control bytes) are 254, 251, 228. Any time a flipped control bytes occurs after a 27, the value should be flipped and the preceding 27 deleted. See page 9 of 142 in BK doc PS12640-44 for further details.

disconnect_from_host()[source]

Disconnects the client from the host.

If the socket is already closed, a recv() call will throw an error. If it doesn’t, we can close the socket.

enable_rgb_output()[source]

The ‘QUERY:GRAB_FRAME “ON”` gets the BK to stream greyscale data (e.g. 640 x 480 x 1),

some applications might want this in RGB format (640 x 480 x 3)
find_first_a_not_preceded_by_b(start_pos, a, b)[source]

Find the first instance of ‘a’ in an array that isn’t preceded by ‘b’

Parameters:
  • start_pos (integer) – Index in array to begin search at
  • a (integer) – Value to find
  • b (integer) – Value not to precede a
Returns:

Index of first a not preceded by b, -1 if none found

Return type:

integer

generate_command_message(message)[source]

Append 0x01 and 0x04 to start/end of message before sending

Parameters: message(string): the message to be sent

get_frame()[source]

Get the next frame from the BK5000.

parse_scanarea_message()[source]

Separate the scanarea response msssage into the separate components.

Message has format: <StartLineX>,<StartLineY>,<StartLineAngle>,<StartDepth>, <StopLineX>,<StopLineY>,<StopLineAngle>,<StopDepth>

Example message: DATA:B_GEOMETRY_SCANAREA:A 0.0017218,-0.000171398, 1.37236,0,-0.00174855,-0.000176821,1.77236,0.0203479;

parse_win_size_message(message)[source]

Extrack the size of the US window from the response message

Message has format “DATA:US_WIN_SIZE 640,480;”

Parameters: message(string): the received message

query_scanarea()[source]

Query the BK5000 for the scan area. (width/height/scanning depth etc.)

query_win_size()[source]

Query the BK5000 for the window/image size

receive_image()[source]

Scan the incoming data stream to find the start and end of the image data.

See BK doc PS12640-44 for further details.

receive_response_message(expected_size=1024)[source]

Receive a message

Stores it under the data class member

Parameters: expected_size(int): the receive message size in bytes

request_stop()[source]

Set the appropriate class member

send_command_message(message)[source]

Send a message through the socket.

Implements a couple of checks to verify the message has been sent correctly.

Parameters: message(string): the message to be sent

start_streaming()[source]

Send a message to start the streaming

stop_streaming()[source]

Send a message to stop the streaming. send_command_message and receive_response_message will throw errors if there is a problem with the socket connection.

class sksurgerybk.interface.bk5000.BKOpenCV(TCP_IP='128.16.0.3', TCP_PORT=7915, TIMEOUT=5, FPS=25)[source]

Bases: object

Display BK data using OpenCV.

start()[source]

Start acquisiton/streaming.

Bases: object

Send BK data over OpenIGTLink.

start()[source]

Start acquisiton/streaming.

stop()[source]

Stop acquisition/streaming.

sksurgerybk.interface.bk5000.main()[source]

Entry point for OpenCV/pyIGTLink.

Module contents
Module contents

scikit-surgerybk

work_in_progress module