Skip to content

Commit

Permalink
ecg gen: add header
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshi-s committed Jan 18, 2024
1 parent 3378295 commit 1b5279e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions codes/ecg-image-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ The basic mode of the tool creates ECG images without distortions. The mode of o
- `-se`: Seed controlling all the random parameters; type: int
- `-r`: Resolution with default being 200; type: int
- `--pad_inches`: Padding of white border along the image with default padding of 0 inches; type: int
- `print_header`: Add text from header file on all the generated images; default: False
- `--num_columns` : Number of columns of the ECG leads. The default(-1) will plot a single column for 2 lead data and 4 columns for the 12 or any other number of lead data. Default: -1; type: int
- `--full_mode`: Sets the lead to add at the bottom of the paper ECG as a long strip obtained from the WFDB record's `.hea` header file, if the lead II is not available plots the first lead from the header file; default: `'II'`; type: str
- `--num_images`: Number of ECG images to be generated; default: all files in the input directory; type: int
- `--random_resolution`: Generate random resolutions of images, if True resolution is randomly picked from the range [50, `-r` + 1] else every image is generated at the `-r` resolution; default: False
- `--random_padding`: Generate random padding widths on images, if True pad inches is randomly picked from the range [0, `--pad_inches` + 1], else every image is padded with `--pad_inches`; default: False
- `--random_resolution`: Generate random resolutions of images, if True resolution is randomly picked from the range [50, `-r`] else every image is generated at the `-r` resolution; default: False
- `--random_padding`: Generate random padding widths on images, if True pad inches is randomly picked from the range [0, `--pad_inches`], else every image is padded with `--pad_inches`; default: False
- `--random_dc`: Add ECG calibration pulse to a random number of generated images. The parameter is the probability of the images having the calibration pulse; type: Float, default: 0 (no calibration pulse). Set to 1 to add the pulse to all images. Make sure that `--random_dc` $\in$ [0, 1].
- `--random_grid_present`: Probability of the generated images having the ECG paper grid; type: Float, default: 1 (adds the grid to all images). Make sure that `--random_grid_present` $\in$ [0, 1]. When 0, the images do not have the background grid.
- `--random_print`: Probability of adding printed text to a random set of images; type: Float, default: 0 (no text added). Make sure that `--random_print` $\in$ [0, 1].
- `--random_add_header`: Probability of adding printed text to a random set of images; type: Float, default: 0 (no text added). Make sure that `--random_add_header` $\in$ [0, 1]. If `--print_header` is True, code prints text on all the images regardless of the `--random_add_header` attribute.
- `--random_bw`: Make random set of images black and white controlled by this parameter; type: Float, default: 0 (generates colored ECG). Make sure that `--random_bw` $\in$ [0, 1].
- `--deterministic_lead`: Add lead names to all generated images; default: True
- `--store_text_bouding_box`: Store bounding box coordinates for the lead names in a text file in the folder output_directory/text_bouding_box; default: False.
Expand Down
8 changes: 6 additions & 2 deletions codes/ecg-image-generator/gen_ecg_image_from_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_parser():

parser.add_argument('-r','--resolution',type=int,required=False,default = 200)
parser.add_argument('--pad_inches',type=int,required=False,default=0)
parser.add_argument('-ph','--print_header',action="store_true",default=False)
parser.add_argument('--num_columns',type=int,default = -1)
parser.add_argument('--full_mode', type=str,default='II')

Expand All @@ -46,7 +47,7 @@ def get_parser():
parser.add_argument('--random_padding',action="store_true",default=False)
parser.add_argument('--random_dc',type=float,default=0)
parser.add_argument('--random_grid_present',type=float,default=1)
parser.add_argument('--random_print',type=float,default=0)
parser.add_argument('--random_add_header',type=float,default=0)
parser.add_argument('--random_bw',type=float,default=0)
parser.add_argument('--deterministic_lead',action="store_true",default=True)
parser.add_argument('--store_text_bounding_box',action="store_true",default=False)
Expand Down Expand Up @@ -103,7 +104,10 @@ def run_single_file(args):
bernoulli_dc = bernoulli(args.random_dc)
bernoulli_bw = bernoulli(args.random_bw)
bernoulli_grid = bernoulli(args.random_grid_present)
bernoulli_add_print = bernoulli(args.random_print)
if args.print_header:
bernoulli_add_print = bernoulli(1)
else:
bernoulli_add_print = bernoulli(args.random_add_header)

font = os.path.join('Fonts',random.choice(os.listdir("Fonts")))

Expand Down
3 changes: 2 additions & 1 deletion codes/ecg-image-generator/gen_ecg_images_from_data_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_parser():

parser.add_argument('-r','--resolution',type=int,required=False,default = 200)
parser.add_argument('--pad_inches',type=int,required=False,default=0)
parser.add_argument('-ph','--print_header', action="store_true",default=False)
parser.add_argument('--num_columns',type=int,default = -1)
parser.add_argument('--full_mode', type=str,default='II')

Expand All @@ -44,7 +45,7 @@ def get_parser():
parser.add_argument('--random_padding',action="store_true",default=False)
parser.add_argument('--random_dc',type=float,default=0)
parser.add_argument('--random_grid_present',type=float,default=1)
parser.add_argument('--random_print',type=float,default=0)
parser.add_argument('--random_add_header',type=float,default=0)
parser.add_argument('--random_bw',type=float,default=0)
parser.add_argument('--deterministic_lead',action="store_true",default=True)
parser.add_argument('--store_text_bounding_box',action="store_true",default=False)
Expand Down

0 comments on commit 1b5279e

Please sign in to comment.