Skip to content

Commit

Permalink
fixing mask subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubMitura14 committed Nov 4, 2021
1 parent 6bb060f commit cfbc73c
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MedEye3d"
uuid = "48a1af7b-3279-4eeb-8f2b-7ca229bb51b1"
authors = ["M.D Jakub Mitura <[email protected]>"]
version = "0.2.0"
version = "0.3.0"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down
12 changes: 6 additions & 6 deletions build/display/GLFW/shadersEtc/Uniforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ uniform!(myuniform, rand(Cfloat, 4, 4))
"""
function uniform! end

@generated function uniform!(location::GLint, values::Vararg{T, N}) where {N, T <: Real}
@generated function uniform!(location, values::Vararg{T, N}) where {N, T <: Real}
suffix = _type_suffix(T)
glFunc = Symbol("glUniform$(N)$suffix")
return :( $(glFunc)(location, values...) )
end

@generated function uniform!(location::GLint, vector::SVector{N, T}) where {N, T <: Real}
@generated function uniform!(location, vector::SVector{N, T}) where {N, T <: Real}
suffix = _type_suffix(T)
glFunc = Symbol("glUniform$(N)$(suffix)v")
return :( $(glFunc)(location, 1, vector) )
end

@generated function uniform!(location::GLint, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real}
@generated function uniform!(location, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real}
glFunc = Symbol(
if N == M
"glUniformMatrix$(N)fv"
Expand All @@ -145,12 +145,12 @@ end
return :( $(glFunc)(location, 1, transposed, Cfloat[matrix...]) )
end

function uniform!(location::GLint, vector::AbstractVector{T}) where {T <: Real}
function uniform!(location, vector::AbstractVector{T}) where {T <: Real}
N = length(vector)
uniform!(location, SVector{N, T}(vector...))
end

function uniform!(location::GLint, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real}
function uniform!(location, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real}
N, M = size(matrix)
uniform!(location, SMatrix{N, M, T}(matrix), transposed)
end
Expand All @@ -159,7 +159,7 @@ end
Gets the location of the uniform variable
identified by `name`.
"""
getuniform(program::GLuint, name::SymString) = glGetUniformLocation(program, string(name))
getuniform(program, name::SymString) = glGetUniformLocation(program, string(name))
"""
@uniforms foo, bar, ... = program
Get the location of `foo`, `bar` and `etc` from `program`,
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MedEye3d"
uuid = "48a1af7b-3279-4eeb-8f2b-7ca229bb51b1"
authors = ["M.D Jakub Mitura <[email protected]>"]
version = "0.1.0"
version = "0.3.0"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down
151 changes: 148 additions & 3 deletions docs/src/loadExampleData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,152 @@ SegmentationDisplay.coordinateDisplay(textureSpecificationsPETCT ,fractionOfMain

Main.SegmentationDisplay.passDataForScrolling(mainScrollDat);

using GLFW
GLFW.PollEvents()

# SegmentationDisplay








# SegmentationDisplay

#I use Simple ITK as most robust
using MedEye3d, Conda,PyCall,Pkg

Conda.pip_interop(true)
Conda.pip("install", "SimpleITK")
Conda.pip("install", "h5py")
sitk = pyimport("SimpleITK")
np= pyimport("numpy")

import MedEye3d
import MedEye3d.ForDisplayStructs
import MedEye3d.ForDisplayStructs.TextureSpec
using ColorTypes
import MedEye3d.SegmentationDisplay

import MedEye3d.DataStructs.ThreeDimRawDat
import MedEye3d.DataStructs.DataToScrollDims
import MedEye3d.DataStructs.FullScrollableDat
import MedEye3d.ForDisplayStructs.KeyboardStruct
import MedEye3d.ForDisplayStructs.MouseStruct
import MedEye3d.ForDisplayStructs.ActorWithOpenGlObjects
import MedEye3d.OpenGLDisplayUtils
import MedEye3d.DisplayWords.textLinesFromStrings
import MedEye3d.StructsManag.getThreeDims

"""
given directory (dirString) to file/files it will return the simple ITK image for futher processing
isMHD when true - data in form of folder with dicom files
isMHD when true - we deal with MHD data
"""
function getImageFromDirectory(dirString,isMHD::Bool, isDicomList::Bool)
#simpleITK object used to read from disk
reader = sitk.ImageSeriesReader()
if(isDicomList)# data in form of folder with dicom files
dicom_names = reader.GetGDCMSeriesFileNames(dirString)
reader.SetFileNames(dicom_names)
return reader.Execute()
elseif(isMHD) #mhd file
return sitk.ReadImage(dirString)
end
end#getPixelDataAndSpacing

"""
becouse Julia arrays is column wise contiguus in memory and open GL expects row wise we need to rotate and flip images
pixels - 3 dimensional array of pixel data
"""
function permuteAndReverse(pixels)
pixels= permutedims(pixels, (3,2,1))
sizz=size(pixels)
for i in 1:sizz[1]
for j in 1:sizz[3]
pixels[i,:,j] = reverse(pixels[i,:,j])
end#
end#
return pixels
end#permuteAndReverse

"""
given simple ITK image it reads associated pixel data - and transforms it by permuteAndReverse functions
it will also return voxel spacing associated with the image
"""
function getPixelsAndSpacing(image)
pixelsArr = np.array(sitk.GetArrayViewFromImage(image))# we need numpy in order for pycall to automatically change it into julia array
spacings = image.GetSpacing()
return ( permuteAndReverse(pixelsArr), spacings )
end#getPixelsAndSpacing

exampleLabel = "C:\\GitHub\\JuliaMedPipe\\data\\liverPrimData\\training-labels\\label\\liver-seg002.mhd"
exampleCTscann = "C:\\GitHub\\JuliaMedPipe\\data\\liverPrimData\\training-scans\\scan\\liver-orig002.mhd"



imagePureCT= getImageFromDirectory(exampleCTscann,true,false)
imageMask= getImageFromDirectory(exampleLabel,true,false)

ctPixelsPure, ctSpacingPure = getPixelsAndSpacing(imagePureCT)
maskPixels, maskSpacing =getPixelsAndSpacing(imageMask)

datToScrollDimsB= MedEye3d.ForDisplayStructs.DataToScrollDims(imageSize= size(ctPixelsPure) ,voxelSize=ctSpacingPure, dimensionToScroll = 3 );
# example of texture specification used - we need to describe all arrays we want to display
listOfTexturesSpec = [
TextureSpec{UInt8}(
name = "goldStandardLiver",
numb= Int32(1),
color = RGB(1.0,0.0,0.0)
,minAndMaxValue= Int8.([0,1])
),
TextureSpec{UInt8}(
name = "manualModif",
numb= Int32(2),
color = RGB(0.0,1.0,0.0)
,minAndMaxValue= UInt8.([0,1])
,isEditable = true
),

TextureSpec{Int16}(
name= "CTIm",
numb= Int32(3),
isMainImage = true,
minAndMaxValue= Int16.([0,100]))
];

fractionOfMainIm= Float32(0.8);
"""
If we want to display some text we need to pass it as a vector of SimpleLineTextStructs
"""
import MedEye3d.DisplayWords.textLinesFromStrings

mainLines= textLinesFromStrings(["main Line1", "main Line 2"]);
supplLines=map(x-> textLinesFromStrings(["sub Line 1 in $(x)", "sub Line 2 in $(x)"]), 1:size(ctPixelsPure)[3] );

"""
If we want to pass 3 dimensional array of scrollable data"""
import MedEye3d.StructsManag.getThreeDims

tupleVect = [("goldStandardLiver",maskPixels) ,("CTIm",ctPixelsPure),("manualModif",zeros(UInt8,size(ctPixelsPure)) ) ]
slicesDat= getThreeDims(tupleVect )

"""
Holds data necessary to display scrollable data
"""
mainScrollDat = FullScrollableDat(dataToScrollDims =datToScrollDimsB
,dimensionToScroll=1 # what is the dimension of plane we will look into at the beginning for example transverse, coronal ...
,dataToScroll= slicesDat
,mainTextToDisp= mainLines
,sliceTextToDisp=supplLines );


SegmentationDisplay.coordinateDisplay(listOfTexturesSpec ,fractionOfMainIm ,datToScrollDimsB ,1000);

Main.SegmentationDisplay.passDataForScrolling(mainScrollDat);




using GLFW
GLFW.PollEvents()

2 changes: 1 addition & 1 deletion src/display/GLFW/SegmentationDisplay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function coordinateDisplay(listOfTextSpecsPrim::Vector{TextureSpec}
# than we set those ..Uniforms, open gl types and using data from arguments to fill texture specifications
mainImageUnifs,listOfTextSpecsMapped= assignUniformsAndTypesToMasks(listOfTextSpecs,shader_program,windowControlStruct)

@info "listOfTextSpecsMapped" listOfTextSpecsMapped
#@info "listOfTextSpecsMapped" listOfTextSpecsMapped
#initializing object that holds data reqired for interacting with opengl
initializedTextures = initializeTextures(listOfTextSpecsMapped,calcDimStruct)

Expand Down
26 changes: 19 additions & 7 deletions src/display/GLFW/shadersEtc/Uniforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ managing uniform values - global values in shaders
module Uniforms
using StaticArrays,ModernGL,Rocket, ..ForDisplayStructs, Dictionaries, Parameters, ColorTypes

export changeMainTextureContribution,changeTextureContribution,coontrolMinMaxUniformVals,createStructsDict, setCTWindow,setMaskColor,setTextureVisibility, setTypeOfMainSampler!
export isMaskDiffViss,changeMainTextureContribution,changeTextureContribution,coontrolMinMaxUniformVals,createStructsDict, setCTWindow,setMaskColor,setTextureVisibility, setTypeOfMainSampler!
export @uniforms
export @uniforms!

Expand Down Expand Up @@ -122,19 +122,19 @@ uniform!(myuniform, rand(Cfloat, 4, 4))
"""
function uniform! end

@generated function uniform!(location::GLint, values::Vararg{T, N}) where {N, T <: Real}
@generated function uniform!(location, values::Vararg{T, N}) where {N, T <: Real}
suffix = _type_suffix(T)
glFunc = Symbol("glUniform$(N)$suffix")
return :( $(glFunc)(location, values...) )
end

@generated function uniform!(location::GLint, vector::SVector{N, T}) where {N, T <: Real}
@generated function uniform!(location, vector::SVector{N, T}) where {N, T <: Real}
suffix = _type_suffix(T)
glFunc = Symbol("glUniform$(N)$(suffix)v")
return :( $(glFunc)(location, 1, vector) )
end

@generated function uniform!(location::GLint, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real}
@generated function uniform!(location, matrix::SMatrix{N, M, T}, transposed::Bool = false) where {N, M, T <: Real}
glFunc = Symbol(
if N == M
"glUniformMatrix$(N)fv"
Expand All @@ -145,12 +145,12 @@ end
return :( $(glFunc)(location, 1, transposed, Cfloat[matrix...]) )
end

function uniform!(location::GLint, vector::AbstractVector{T}) where {T <: Real}
function uniform!(location, vector::AbstractVector{T}) where {T <: Real}
N = length(vector)
uniform!(location, SVector{N, T}(vector...))
end

function uniform!(location::GLint, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real}
function uniform!(location, matrix::AbstractMatrix{T}, transposed::Bool = false) where {T <: Real}
N, M = size(matrix)
uniform!(location, SMatrix{N, M, T}(matrix), transposed)
end
Expand All @@ -159,7 +159,7 @@ end
Gets the location of the uniform variable
identified by `name`.
"""
getuniform(program::GLuint, name::SymString) = glGetUniformLocation(program, string(name))
getuniform(program, name::SymString) = glGetUniformLocation(program, string(name))
"""
@uniforms foo, bar, ... = program
Get the location of `foo`, `bar` and `etc` from `program`,
Expand Down Expand Up @@ -259,6 +259,18 @@ function setMaskColor(color::RGB, uniformsStore ::MaskTextureUniforms)

end#setMaskColor

"""
sets color of the mask
"""
function isMaskDiffViss( isMaskDiffrenceVisUnifs)
@uniforms! begin
isMaskDiffrenceVisUnifs:=1
end

end#isMaskDiffViss



"""
sets visibility of the texture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ function displayMaskDiffrence(maskA::TextureSpec, maskB::TextureSpec,actor::Sync
reactivateMainObj(shader_prog, newForDisp.vbo,actor.actor.calcDimsStruct )
activateTextures(listOfTextSpecsc )
#making diffrence visible
@uniforms! begin
dispObj.mainImageUniforms.isMaskDiffrenceVis:=1
end
isMaskDiffViss(dispObj.mainImageUniforms.isMaskDiffrenceVis)
# @uniforms! begin
# dispObj.mainImageUniforms.isMaskDiffrenceVis:=1
# end
setTextureVisibility(false,maskA.uniforms )
setTextureVisibility(false,maskB.uniforms )
basicRender(actor.actor.mainForDisplayObjects.window)
Expand Down

2 comments on commit cfbc73c

@jakubMitura14
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/48161

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" cfbc73c854a43d06ac7387e5d5437a45a177db85
git push origin v0.3.0

Please sign in to comment.