Alternative versions of SaveBitMap and IntQuant for adjustments to the color level input
This commit is contained in:
parent
4ea5d8e119
commit
df0d82910b
62
app.jl
62
app.jl
@ -13,6 +13,7 @@ using Images
|
|||||||
using LinearAlgebra
|
using LinearAlgebra
|
||||||
using NativeFileDialog # Opens the file explorer depending on the OS
|
using NativeFileDialog # Opens the file explorer depending on the OS
|
||||||
using StipplePlotly
|
using StipplePlotly
|
||||||
|
include("./julia_imzML_visual.jl")
|
||||||
@genietools
|
@genietools
|
||||||
|
|
||||||
# == Code import ==
|
# == Code import ==
|
||||||
@ -54,13 +55,13 @@ function loadImgPlot(interfaceImg::String)
|
|||||||
cleaned_img=lstrip(cleaned_img, '/')
|
cleaned_img=lstrip(cleaned_img, '/')
|
||||||
var=joinpath("./public", cleaned_img)
|
var=joinpath("./public", cleaned_img)
|
||||||
img=load(var)
|
img=load(var)
|
||||||
println("type of img: $(typeof(img))")
|
#println("type of img: $(typeof(img))")
|
||||||
# Convert to grayscale
|
# Convert to grayscale
|
||||||
img_gray=Gray.(img)
|
img_gray=Gray.(img)
|
||||||
img_array=Array(img_gray)
|
img_array=Array(img_gray)
|
||||||
#println(typeof(img_array))
|
#println(typeof(img_array))
|
||||||
elevation=Float32.(Array(img_array)) ./ 255.0
|
elevation=Float32.(Array(img_array)) ./ 255.0
|
||||||
println("type of elevation: $(typeof(elevation))")
|
#println("type of elevation: $(typeof(elevation))")
|
||||||
# Get the X, Y coordinates of the image
|
# Get the X, Y coordinates of the image
|
||||||
height, width=size(img_array)
|
height, width=size(img_array)
|
||||||
#println("height: $(height), width: $(width)")
|
#println("height: $(height), width: $(width)")
|
||||||
@ -203,10 +204,12 @@ function loadSurfacePlot(interfaceImg::String)
|
|||||||
aspectratio=aspect_ratio
|
aspectratio=aspect_ratio
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if size(elevation_smoothed, 1) < size(elevation_smoothed, 2)
|
|
||||||
# Transpose the elevation_smoothed array if Y axis is longer than X axis to fix chopping
|
# Transpose the elevation_smoothed array if Y axis is longer than X axis to fix chopping
|
||||||
elevation_smoothed=transpose(elevation_smoothed)
|
elevation_smoothed=transpose(elevation_smoothed)
|
||||||
|
if size(elevation_smoothed, 1) < size(elevation_smoothed, 2)
|
||||||
Y=-Y
|
Y=-Y
|
||||||
|
else
|
||||||
|
X=-X
|
||||||
end
|
end
|
||||||
|
|
||||||
trace3D=PlotlyBase.surface(
|
trace3D=PlotlyBase.surface(
|
||||||
@ -244,7 +247,7 @@ function crossLinesPlot(x, y, maxwidth, maxheight)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# == Reactive code ==
|
# == Reactive code ==
|
||||||
# reactive code to make the UI interactive
|
# Reactive code to make the UI interactive
|
||||||
@app begin
|
@app begin
|
||||||
# == Reactive variables ==
|
# == Reactive variables ==
|
||||||
# reactive variables exist in both the Julia backend and the browser with two-way synchronization
|
# reactive variables exist in both the Julia backend and the browser with two-way synchronization
|
||||||
@ -476,6 +479,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
@onbutton mainProcess begin
|
@onbutton mainProcess begin
|
||||||
|
#@onchange Nmass begin
|
||||||
progress=true # Start progress button animation
|
progress=true # Start progress button animation
|
||||||
btnStartDisable=true # We disable the button to avoid multiple requests
|
btnStartDisable=true # We disable the button to avoid multiple requests
|
||||||
btnPlotDisable=true
|
btnPlotDisable=true
|
||||||
@ -489,25 +493,21 @@ end
|
|||||||
spectra=LoadImzml(full_route)
|
spectra=LoadImzml(full_route)
|
||||||
msg="File loaded. Creating Spectra with the specific mass and tolerance, please be patient."
|
msg="File loaded. Creating Spectra with the specific mass and tolerance, please be patient."
|
||||||
slice=GetSlice(spectra, Nmass, Tol)
|
slice=GetSlice(spectra, Nmass, Tol)
|
||||||
fig=CairoMakie.Figure(size=(140, 440)) # Container
|
fig=CairoMakie.Figure(size=(128, 256)) # Container
|
||||||
# Append a query string to force the image to refresh
|
# Append a query string to force the image to refresh
|
||||||
timestamp=string(time_ns())
|
timestamp=string(time_ns())
|
||||||
if triqEnabled # If we have TrIQ
|
if triqEnabled # If we have TrIQ
|
||||||
if colorLevel < 4 || colorLevel > 256 || triqProb < 0.8 || triqProb > 1
|
if colorLevel < 2 || colorLevel > 256 || triqProb < 0.8 || triqProb > 1
|
||||||
msg="Incorrect TrIQ values, please adjust accordingly and try again."
|
msg="Incorrect TrIQ values, please adjust accordingly and try again."
|
||||||
warning_msg=true
|
warning_msg=true
|
||||||
else
|
else
|
||||||
image_path=joinpath("./public", "TrIQ_$(text_nmass).bmp")
|
image_path=joinpath("./public", "TrIQ_$(text_nmass).bmp")
|
||||||
SaveBitmap(joinpath("public", "TrIQ_$(text_nmass).bmp"),TrIQ(slice, Int(colorLevel), triqProb),ViridisPalette)
|
sliceTriq=TrIQ(slice, Int(colorLevel), triqProb)
|
||||||
# Flip te image vertically then save it again
|
#println("slice raw: $(typeof(slice))")
|
||||||
img=load(image_path)
|
#println("TriQ matrix: $(typeof(sliceTriq))")
|
||||||
if size(img, 1) > size(img, 2) # fix to taller images
|
sliceTriq=reverse(sliceTriq, dims=2)
|
||||||
img=reverse(permutedims(img, (2, 1)), dims=1)
|
##SaveBitmap(joinpath("public", "TrIQ_$(text_nmass).bmp"),sliceTriq,ViridisPalette)
|
||||||
end
|
SaveBitmapCl(joinpath("public", "TrIQ_$(text_nmass).bmp"),sliceTriq,ViridisPalette)
|
||||||
flipped_img=reverse(img, dims=1)
|
|
||||||
imgWidth=size(flipped_img, 2)
|
|
||||||
imgHeight=size(flipped_img, 1)
|
|
||||||
save(image_path, flipped_img)
|
|
||||||
# Use timestamp to refresh image interface container
|
# Use timestamp to refresh image interface container
|
||||||
imgIntT="/TrIQ_$(text_nmass).bmp?t=$(timestamp)"
|
imgIntT="/TrIQ_$(text_nmass).bmp?t=$(timestamp)"
|
||||||
plotdataImgT, plotlayoutImgT, imgWidth, imgHeight=loadImgPlot(imgIntT)
|
plotdataImgT, plotlayoutImgT, imgWidth, imgHeight=loadImgPlot(imgIntT)
|
||||||
@ -515,12 +515,8 @@ end
|
|||||||
current_triq="TrIQ_$(text_nmass).bmp"
|
current_triq="TrIQ_$(text_nmass).bmp"
|
||||||
msgtriq="TrIQ image with the Nmass of $(replace(text_nmass, "_" => "."))"
|
msgtriq="TrIQ image with the Nmass of $(replace(text_nmass, "_" => "."))"
|
||||||
# Create colorbar
|
# Create colorbar
|
||||||
#ticks=round.(range(0, stop=maximum(TrIQ(slice, Int(colorLevel), triqProb)), length=10), sigdigits=3)
|
ticks=round.(range(0, (stop=maximum(sliceTriq)*triqProb), length=15), sigdigits=3)
|
||||||
#println("ticks: $(round.(range(0, stop=maximum(TrIQ(slice, Int(colorLevel), triqProb)), length=10), sigdigits=3))")
|
Colorbar(fig[1, 1], colormap=cgrad(:viridis, colorLevel, categorical=true), limits=(0, maximum(sliceTriq)*triqProb),ticks=ticks, label="Intensity", size = 25)
|
||||||
ticks=round.(range(0, (stop=maximum(slice)*triqProb), length=15), sigdigits=3)
|
|
||||||
#println("ticks 2: $(round.(range(0, (stop=maximum(slice)*triqProb), length=15), sigdigits=3))")
|
|
||||||
#Colorbar(fig[1, 1], colormap=rgb_ViridisPalette, limits=(0, maximum(TrIQ(slice, Int(colorLevel), triqProb))),ticks=ticks, label="Intensity")
|
|
||||||
Colorbar(fig[1, 1], colormap=cgrad(:viridis, colorLevel, categorical=true), limits=(0, maximum(slice)*triqProb),ticks=ticks, label="Intensity", size = 25)
|
|
||||||
save("public/colorbar_TrIQ_$(text_nmass).png", fig)
|
save("public/colorbar_TrIQ_$(text_nmass).png", fig)
|
||||||
colorbarT="/colorbar_TrIQ_$(text_nmass).png?t=$(timestamp)"
|
colorbarT="/colorbar_TrIQ_$(text_nmass).png?t=$(timestamp)"
|
||||||
# Get current colorbar
|
# Get current colorbar
|
||||||
@ -537,16 +533,13 @@ end
|
|||||||
end
|
end
|
||||||
else # If we don't use TrIQ
|
else # If we don't use TrIQ
|
||||||
image_path=joinpath("./public", "MSI_$(text_nmass).bmp")
|
image_path=joinpath("./public", "MSI_$(text_nmass).bmp")
|
||||||
SaveBitmap(joinpath("public", "MSI_$(text_nmass).bmp"),IntQuant(slice),ViridisPalette)
|
##sliceQuant=IntQuant(slice)
|
||||||
# Flip te image vertically then save it again
|
sliceQuant=IntQuantCl(slice,colorLevel)
|
||||||
img=load(image_path)
|
#println("slice raw: $(typeof(slice))")
|
||||||
if size(img, 1) > size(img, 2) # fix to taller images
|
#println("slice in intQuant: $(typeof(sliceQuant))")
|
||||||
img=reverse(permutedims(img, (2, 1)), dims=1)
|
sliceQuant=reverse(sliceQuant, dims=2)
|
||||||
end
|
##SaveBitmap(joinpath("public", "MSI_$(text_nmass).bmp"),sliceQuant,ViridisPalette)
|
||||||
flipped_img=reverse(img, dims=1)
|
SaveBitmapCl(joinpath("public", "MSI_$(text_nmass).bmp"),sliceQuant,ViridisPalette)
|
||||||
imgWidth=size(flipped_img, 2)
|
|
||||||
imgHeight=size(flipped_img, 1)
|
|
||||||
save(image_path, flipped_img)
|
|
||||||
# Use timestamp to refresh image interface container
|
# Use timestamp to refresh image interface container
|
||||||
imgInt="/MSI_$(text_nmass).bmp?t=$(timestamp)"
|
imgInt="/MSI_$(text_nmass).bmp?t=$(timestamp)"
|
||||||
plotdataImg, plotlayoutImg, imgWidth, imgHeight=loadImgPlot(imgInt)
|
plotdataImg, plotlayoutImg, imgWidth, imgHeight=loadImgPlot(imgInt)
|
||||||
@ -555,9 +548,8 @@ end
|
|||||||
msgimg="Image with the Nmass of $(replace(text_nmass, "_" => "."))"
|
msgimg="Image with the Nmass of $(replace(text_nmass, "_" => "."))"
|
||||||
# Create colorbar
|
# Create colorbar
|
||||||
#ticks=round.(range(0, stop=maximum(slice), length=10), sigdigits=3)
|
#ticks=round.(range(0, stop=maximum(slice), length=10), sigdigits=3)
|
||||||
ticks=round.(range(0, stop=maximum(slice), length=15), sigdigits=3)
|
ticks=round.(range(0, stop=maximum(sliceQuant), length=15), sigdigits=3)
|
||||||
#Colorbar(fig[1, 1], colormap=rgb_ViridisPalette, limits=(0, maximum(slice)),ticks=ticks, label="Intensity")
|
Colorbar(fig[1, 1], colormap=cgrad(:viridis, colorLevel, categorical=true), limits=(0, maximum(sliceQuant)),ticks=ticks, label="Intensity", size = 25)
|
||||||
Colorbar(fig[1, 1], colormap=cgrad(:viridis, 256, categorical=true), limits=(0, maximum(slice)),ticks=ticks, label="Intensity", size = 25)
|
|
||||||
save("public/colorbar_MSI_$(text_nmass).png", fig)
|
save("public/colorbar_MSI_$(text_nmass).png", fig)
|
||||||
colorbar="/colorbar_MSI_$(text_nmass).png?t=$(timestamp)"
|
colorbar="/colorbar_MSI_$(text_nmass).png?t=$(timestamp)"
|
||||||
# Get current colorbar
|
# Get current colorbar
|
||||||
|
|||||||
22
app.jl.html
22
app.jl.html
@ -57,21 +57,29 @@
|
|||||||
<p id="lblFullRoute">full route: {{full_route}}</p>
|
<p id="lblFullRoute">full route: {{full_route}}</p>
|
||||||
<!-- Variable Manipulation -->
|
<!-- Variable Manipulation -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="st-col col-12 col-sm q-ma-sm">
|
<div class="st-col col-4 col-sm q-ma-sm">
|
||||||
<q-input standout="custom-standout" id="textNmass" step="0.01" v-model="Nmass"
|
<q-input standout="custom-standout" id="textNmass" step="0.01" v-model="Nmass"
|
||||||
label="Mass-to-charge ratio of interest" type="number"
|
label="Mass-to-charge ratio of interest" type="number"
|
||||||
:rules="[ val => !!val || '* Required', val => val >= 0.0 || 'Need positive mass values',]"></q-input>
|
:rules="[ val => !!val || '* Required', val => val >= 0.0 || 'Need positive mass values',]"></q-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="st-col col-12 col-sm q-ma-sm">
|
<div class="st-col col-4 col-sm q-ma-sm">
|
||||||
<q-input standout="custom-standout" id="textTol" step="0.05" v-model="Tol"
|
<q-input standout="custom-standout" id="textTol" step="0.05" v-model="Tol"
|
||||||
label="Mass-to-charge ratio tolerance" type="number"
|
label="Mass-to-charge ratio tolerance" type="number"
|
||||||
:rules="[val => !!val || '* Required', val => val >= 0.0 && val <= 1.0 || 'Needs to be in range between 0 and 1',]"></q-input>
|
:rules="[val => !!val || '* Required', val => val >= 0.0 && val <= 1.0 || 'Needs to be in range between 0 and 1',]"></q-input>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="st-col col-4 col-sm q-ma-sm">
|
||||||
|
<q-input standout="custom-standout" id="textcolorLevel" step="1" v-model="colorLevel"
|
||||||
|
label="Color level" type="number" :rules="[
|
||||||
|
val => triqEnabled ? ( '* Required', val >= 4 && val <= 256 || 'Needs to be in range between 2 and 256') : true
|
||||||
|
]"></q-input>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- Triq Variable Manipulation -->
|
<!-- Triq Variable Manipulation and filters-->
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<div class="st-col col-6 col-sm q-ma-sm">
|
<div class="st-col col-6 col-sm q-ma-sm">
|
||||||
|
<q-toggle id="btnEnableMFilter" v-on:click="MFilterEnabled" v-model="MFilterEnabled" color="green"
|
||||||
|
label="Add Median Filter"></q-toggle>
|
||||||
<q-toggle id="btnEnableTriq" v-on:click="triqEnabled" v-model="triqEnabled" color="blue"
|
<q-toggle id="btnEnableTriq" v-on:click="triqEnabled" v-model="triqEnabled" color="blue"
|
||||||
label="Add Threshold Intensity Quantization (TrIQ)"></q-toggle>
|
label="Add Threshold Intensity Quantization (TrIQ)"></q-toggle>
|
||||||
</div>
|
</div>
|
||||||
@ -82,12 +90,8 @@
|
|||||||
val => triqEnabled ? ( '* Required', val >= 0.8 && val <= 1 || 'Needs to be in range between 0.8 and 1') : true
|
val => triqEnabled ? ( '* Required', val >= 0.8 && val <= 1 || 'Needs to be in range between 0.8 and 1') : true
|
||||||
]" :readonly="!triqEnabled" :disable="!triqEnabled"></q-input>
|
]" :readonly="!triqEnabled" :disable="!triqEnabled"></q-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="st-col col-4 col-sm-4 q-ma-sm">
|
<!--<div class="st-col col-4 col-sm-4 q-ma-sm">
|
||||||
<q-input standout="custom-standout" id="textcolorLevel" step="1" v-model="colorLevel"
|
</div>-->
|
||||||
label="TrIQ color levels" type="number" :rules="[
|
|
||||||
val => triqEnabled ? ( '* Required', val >= 4 && val <= 256 || 'Needs to be in range between 2 and 256') : true
|
|
||||||
]" :readonly="!triqEnabled" :disable="!triqEnabled"></q-input>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Spectra Plot Manipulation -->
|
<!-- Spectra Plot Manipulation -->
|
||||||
|
|||||||
64
julia_imzML_visual.jl
Normal file
64
julia_imzML_visual.jl
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# IntQuantCl is originally a function of julia mzMl imzML with the adition
|
||||||
|
# of altering the scale of the colors according to colorlevel.
|
||||||
|
function IntQuantCl( slice , colorLevel)
|
||||||
|
# Compute scale factor for amplitude discretization
|
||||||
|
lower = minimum( slice )
|
||||||
|
scale = colorLevel / maximum( slice )
|
||||||
|
dim = size( slice )
|
||||||
|
image = zeros( UInt8, dim[1], dim[2] )
|
||||||
|
for i in 1:length( slice )
|
||||||
|
image[i] = convert( UInt8, floor( slice[i] * scale + 0.5 ) )
|
||||||
|
end
|
||||||
|
return image
|
||||||
|
end
|
||||||
|
|
||||||
|
# SaveBitmap is also originally a function of the mzML imzML library in julia,
|
||||||
|
# This function dinamically adjust the color palete adjusting to the ammount of colors
|
||||||
|
# available in pixmap
|
||||||
|
function SaveBitmapCl( name,
|
||||||
|
pixMap::Array{UInt8,2},
|
||||||
|
colorTable::Array{UInt32,1} )
|
||||||
|
# Get image dimensions
|
||||||
|
dim = size( pixMap )
|
||||||
|
if length( dim ) != 2
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
# Compute row padding
|
||||||
|
padding = ( 4 - dim[1] & 0x3 ) & 0x3
|
||||||
|
# Compute file dimensions. Header = 14 + 40 + ( 256 * 4 ) = 1078
|
||||||
|
offset = 1078
|
||||||
|
imgBytes = dim[2] * ( dim[1] + padding )
|
||||||
|
# Create file
|
||||||
|
stream = open( name, "w" )
|
||||||
|
# Save file header
|
||||||
|
write( stream, UInt16( 0x4D42 ) )
|
||||||
|
write( stream, UInt32[ offset + imgBytes, 0 , offset ] )
|
||||||
|
# Save info header
|
||||||
|
write( stream, UInt32[ 40, dim[1], dim[2], 0x80001, 0 ] )
|
||||||
|
write( stream, UInt32[ imgBytes, 0, 0, 256, 0 ] )
|
||||||
|
# Get unique colors displayed in pixMap
|
||||||
|
unique_colors = unique(vec(pixMap))
|
||||||
|
n_colors = length(unique_colors)
|
||||||
|
# Color levels can't surpass 256
|
||||||
|
levels = min(n_colors, 256)
|
||||||
|
extendedColorTable = zeros(UInt32, 256)
|
||||||
|
for i in 1:256
|
||||||
|
idx = ceil(Int, i * levels / 256)
|
||||||
|
extendedColorTable[i] = colorTable[idx]
|
||||||
|
end
|
||||||
|
write(stream, extendedColorTable)
|
||||||
|
# Save image pixels
|
||||||
|
if padding == 0
|
||||||
|
for i = 1:dim[2]
|
||||||
|
write( stream, pixMap[:,i] )
|
||||||
|
end
|
||||||
|
else
|
||||||
|
zeroPad = zeros( UInt8, padding )
|
||||||
|
for i in 1:dim[2]
|
||||||
|
write( stream, pixMap[:,i] )
|
||||||
|
write( stream, zeroPad )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# Close file
|
||||||
|
close( stream )
|
||||||
|
end
|
||||||
@ -3,6 +3,7 @@ Pkg.activate(".")
|
|||||||
Pkg.instantiate()
|
Pkg.instantiate()
|
||||||
Pkg.gc()
|
Pkg.gc()
|
||||||
|
|
||||||
|
"""
|
||||||
packages = [
|
packages = [
|
||||||
"GenieFramework", "Libz", "PlotlyBase", "CairoMakie", "Colors",
|
"GenieFramework", "Libz", "PlotlyBase", "CairoMakie", "Colors",
|
||||||
"Statistics", "NaturalSort", "Genie",
|
"Statistics", "NaturalSort", "Genie",
|
||||||
@ -20,6 +21,7 @@ end
|
|||||||
if !("julia_mzML_imzML" in keys(Pkg.dependencies()))
|
if !("julia_mzML_imzML" in keys(Pkg.dependencies()))
|
||||||
Pkg.add(url="https://github.com/CINVESTAV-LABI/julia_mzML_imzML")
|
Pkg.add(url="https://github.com/CINVESTAV-LABI/julia_mzML_imzML")
|
||||||
end
|
end
|
||||||
|
"""
|
||||||
|
|
||||||
using Genie
|
using Genie
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user