-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cecd3f2
commit 98bfc9f
Showing
10 changed files
with
1,150 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,16 @@ uuid = "308a64e0-2da8-4ffc-993f-c99ea7c8dc9b" | |
authors = ["Wenbo Li <[email protected]> and contributors"] | ||
version = "1.0.0-DEV" | ||
|
||
[deps] | ||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" | ||
DICOM = "a26e6606-dd52-5f6a-a97f-4f611373d757" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" | ||
NIfTI = "a3a9e032-41b5-5fc4-967a-a6b7a19844d3" | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
|
||
[compat] | ||
julia = "1" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
# imageToolBox | ||
|
||
[](https://github.com/Wenbo Li/imageToolBox.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using DICOM, Statistics | ||
|
||
""" | ||
This function reads the dicom file. | ||
- input: | ||
1. path to the dicom file | ||
- output: | ||
1. dcm_data | ||
2. SID | ||
3. V_P | ||
4. image | ||
""" | ||
function read_dicom(path_to_file::String) | ||
dcm_data = dcm_parse(path_to_file) | ||
# image | ||
image = dcm_data[(0x7fe0, 0x0010)] | ||
# v_p | ||
LorR = "" | ||
try | ||
LorR = uppercase(dcm_data[(0x0020,0x0062)]) | ||
catch e | ||
println("---------Error---------") | ||
println(e) | ||
println(curr_path) | ||
println("---------Error---------") | ||
end | ||
V_P = "" | ||
try | ||
V_P = uppercase(dcm_data[(0x0018,0x5101)]) | ||
catch e | ||
println("---------Error---------") | ||
println(e) | ||
println(curr_path) | ||
println("---------Error---------") | ||
end | ||
curr_key = LorR*" "*V_P | ||
# SID | ||
sid = [(0x0010, 0x0020)] | ||
return dcm_data, sid, curr_key, image | ||
end | ||
|
||
""" | ||
This function gets the number of patches needed for a iamge. | ||
- input: | ||
1. Matrix of Float32: the image | ||
2. Matrix of Float32: the roi | ||
3. Matrix of Float32: the binary mask representing the breast area. | ||
- optional input: | ||
1. Float64: `thd`. The threshold of percentage of the white area. Default = 0.35 | ||
2. Int: 'patch_size'. The size of each patch. Default = 256 | ||
- output: | ||
1. int: Number of without-BAC patches. | ||
2. int: Number of with-BAC patches. | ||
""" | ||
function get_num_of_patches(img::Matrix{Float32}, lbl::Matrix{Float32}, mask::Matrix{Float32}; thd = 0.35, patch_size = 256) | ||
patch_size_half = round(Int, patch_size/2) | ||
s = size(img) | ||
x = ceil(Int, s[1]/patch_size) + floor(Int, (s[1]-patch_size_half)/patch_size) | ||
y = ceil(Int, s[2]/patch_size) + floor(Int, (s[2]-patch_size_half)/patch_size) | ||
ct_empty, ct_non_empty = 0, 0 | ||
for i = 1 : x-1 | ||
x_start = 1+(i-1)*patch_size_half | ||
x_end = x_start+patch_size-1 | ||
for j = 1 : y-1 | ||
y_start = 1+(j-1)*patch_size_half | ||
y_end = y_start+patch_size-1 | ||
# check if this is forgounrd | ||
if mean(mask[x_start:x_end, y_start:y_end]) > thd | ||
# check if contains BAC | ||
if sum(lbl[x_start:x_end, y_start:y_end]) > 0 | ||
ct_non_empty += 1 | ||
else | ||
ct_empty += 1 | ||
end | ||
end | ||
end | ||
# right col | ||
y_start, y_end = s[2]-patch_size+1, s[2] | ||
# check if this is forgounrd | ||
if mean(mask[x_start:x_end, y_start:y_end]) > thd | ||
# check if contains BAC | ||
if sum(lbl[x_start:x_end, y_start:y_end]) > 0 | ||
ct_non_empty += 1 | ||
else | ||
ct_empty += 1 | ||
end | ||
end | ||
end | ||
# last row | ||
x_start, x_end = s[1]-patch_size+1, s[1] | ||
for j = 1 : y-1 | ||
y_start = 1+(j-1)*patch_size_half | ||
y_end = y_start+patch_size-1 | ||
# check if this is forgounrd | ||
if mean(mask[x_start:x_end, y_start:y_end]) > thd | ||
# check if contains BAC | ||
if sum(lbl[x_start:x_end, y_start:y_end]) > 0 | ||
ct_non_empty += 1 | ||
else | ||
ct_empty += 1 | ||
end | ||
end | ||
end | ||
# right col | ||
y_start, y_end = s[2]-patch_size+1, s[2] | ||
# check if this is forgounrd | ||
if mean(mask[x_start:x_end, y_start:y_end]) > thd | ||
# check if contains BAC | ||
if sum(lbl[x_start:x_end, y_start:y_end]) > 0 | ||
ct_non_empty += 1 | ||
else | ||
ct_empty += 1 | ||
end | ||
end | ||
return ct_empty, ct_non_empty | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
module imageToolBox | ||
|
||
# Write your package code here. | ||
using Pkg | ||
Pkg.activate("..") | ||
Pkg.instantiate() | ||
|
||
end | ||
include("dicom_tools.jl") | ||
include("nifty_tools.jl") | ||
include("png_tools.jl") | ||
include("other_tools.jl") | ||
|
||
export save_to_csv, get_last_edit_time, search_files_by_ext, search_files_by_name, binary_search_SID | ||
export zoom_pixel_values, copy_file, clean_directory, normalize_img | ||
export read_png, get_breast_mask | ||
export read_dicom, get_num_of_patches | ||
|
||
end |
Empty file.
Oops, something went wrong.