Fixed bounding error in the median filter application
This commit is contained in:
parent
63c7428214
commit
2b6ec4937f
13
app.jl
13
app.jl
@ -248,13 +248,11 @@ include("./julia_imzML_visual.jl")
|
|||||||
@onbutton btnSearch begin
|
@onbutton btnSearch begin
|
||||||
full_route=pick_file(; filterlist="imzML,mzML")
|
full_route=pick_file(; filterlist="imzML,mzML")
|
||||||
if isnothing(full_route)
|
if isnothing(full_route)
|
||||||
#println("No file selected")
|
|
||||||
msg="No file selected"
|
msg="No file selected"
|
||||||
warning_msg=true
|
warning_msg=true
|
||||||
btnStartDisable=true
|
btnStartDisable=true
|
||||||
else
|
else
|
||||||
if endswith(full_route, "imzML") # Case if the file loaded is imzML
|
if endswith(full_route, "imzML") # Case if the file loaded is imzML
|
||||||
#println("Selected file path: ", full_route)
|
|
||||||
btnStartDisable=false
|
btnStartDisable=false
|
||||||
btnPlotDisable=false
|
btnPlotDisable=false
|
||||||
# Splitting the route with regex from imzml to mzml so the plotting can work
|
# Splitting the route with regex from imzml to mzml so the plotting can work
|
||||||
@ -297,10 +295,8 @@ include("./julia_imzML_visual.jl")
|
|||||||
msg="File exists, Nmass=$(Nmass) Tol=$(Tol). Loading file will begin, please be patient."
|
msg="File exists, Nmass=$(Nmass) Tol=$(Tol). Loading file will begin, please be patient."
|
||||||
try
|
try
|
||||||
spectra=LoadImzml(full_route)
|
spectra=LoadImzml(full_route)
|
||||||
println(typeof(spectra))
|
|
||||||
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=GetMzSliceJl(spectra,Nmass,Tol)
|
slice=GetMzSliceJl(spectra,Nmass,Tol)
|
||||||
println(typeof(slice))
|
|
||||||
fig=CairoMakie.Figure(size=(150, 250)) # Container
|
fig=CairoMakie.Figure(size=(150, 250)) # 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())
|
||||||
@ -315,7 +311,6 @@ include("./julia_imzML_visual.jl")
|
|||||||
try
|
try
|
||||||
slice=GetMzSliceJl(spectra, Nmass, Tol)
|
slice=GetMzSliceJl(spectra, Nmass, Tol)
|
||||||
sliceTriq=TrIQ(slice, colorLevel, triqProb)
|
sliceTriq=TrIQ(slice, colorLevel, triqProb)
|
||||||
println(typeof(sliceTriq))
|
|
||||||
if MFilterEnabled # If the Median filter is ON
|
if MFilterEnabled # If the Median filter is ON
|
||||||
sliceTriq=medianFilterjl(sliceTriq)
|
sliceTriq=medianFilterjl(sliceTriq)
|
||||||
end
|
end
|
||||||
@ -354,12 +349,11 @@ include("./julia_imzML_visual.jl")
|
|||||||
image_path=joinpath("./public", "MSI_$(text_nmass).bmp")
|
image_path=joinpath("./public", "MSI_$(text_nmass).bmp")
|
||||||
try
|
try
|
||||||
sliceQuant=IntQuantCl(slice,Int(colorLevel-1))
|
sliceQuant=IntQuantCl(slice,Int(colorLevel-1))
|
||||||
println(typeof(sliceQuant))
|
|
||||||
if MFilterEnabled # If the Median filter is ON
|
if MFilterEnabled # If the Median filter is ON
|
||||||
sliceQuant=medianFilterjl(sliceQuant)
|
sliceQuant=medianFilterjl(sliceQuant)
|
||||||
end
|
end
|
||||||
catch e
|
catch e
|
||||||
println("The error is in the non triq slice: $e")
|
msg="Warning: $e"
|
||||||
end
|
end
|
||||||
sliceQuant=reverse(sliceQuant, dims=2)
|
sliceQuant=reverse(sliceQuant, dims=2)
|
||||||
SaveBitmapCl(joinpath("public", "MSI_$(text_nmass).bmp"),sliceQuant,ViridisPalette)
|
SaveBitmapCl(joinpath("public", "MSI_$(text_nmass).bmp"),sliceQuant,ViridisPalette)
|
||||||
@ -435,7 +429,6 @@ include("./julia_imzML_visual.jl")
|
|||||||
xSpectraMz=mean(spectraMz[1,:])
|
xSpectraMz=mean(spectraMz[1,:])
|
||||||
ySpectraMz=mean(spectraMz[2,:])
|
ySpectraMz=mean(spectraMz[2,:])
|
||||||
catch e
|
catch e
|
||||||
#println("an error was found: $e")
|
|
||||||
xSpectraMz=spectraMz[1,1]
|
xSpectraMz=spectraMz[1,1]
|
||||||
ySpectraMz=spectraMz[2,1]
|
ySpectraMz=spectraMz[2,1]
|
||||||
end
|
end
|
||||||
@ -779,7 +772,6 @@ include("./julia_imzML_visual.jl")
|
|||||||
catch e
|
catch e
|
||||||
msg="Failed to load and process image: $e"
|
msg="Failed to load and process image: $e"
|
||||||
warning_msg=true
|
warning_msg=true
|
||||||
println(msg)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
msg="Image could not be 3d plotted"
|
msg="Image could not be 3d plotted"
|
||||||
@ -820,7 +812,6 @@ include("./julia_imzML_visual.jl")
|
|||||||
catch e
|
catch e
|
||||||
msg="Failed to load and process image: $e"
|
msg="Failed to load and process image: $e"
|
||||||
warning_msg=true
|
warning_msg=true
|
||||||
println(msg)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
msg="Image could not be 3d plotted"
|
msg="Image could not be 3d plotted"
|
||||||
@ -863,7 +854,6 @@ include("./julia_imzML_visual.jl")
|
|||||||
catch e
|
catch e
|
||||||
msg="Failed to load and process image: $e"
|
msg="Failed to load and process image: $e"
|
||||||
warning_msg=true
|
warning_msg=true
|
||||||
println(msg)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
msg="Image could not be 2D plotted"
|
msg="Image could not be 2D plotted"
|
||||||
@ -905,7 +895,6 @@ include("./julia_imzML_visual.jl")
|
|||||||
catch e
|
catch e
|
||||||
msg="Failed to load and process image: $e"
|
msg="Failed to load and process image: $e"
|
||||||
warning_msg=true
|
warning_msg=true
|
||||||
println(msg)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
msg="Image could not be 2D plotted"
|
msg="Image could not be 2D plotted"
|
||||||
|
|||||||
@ -389,23 +389,19 @@ end
|
|||||||
# with the close pixels just from the sides to reduce noise.
|
# with the close pixels just from the sides to reduce noise.
|
||||||
# This one in particular is a midpoint fiter from a 3x3 neighbour area
|
# This one in particular is a midpoint fiter from a 3x3 neighbour area
|
||||||
function medianFilterjl(pixMap)
|
function medianFilterjl(pixMap)
|
||||||
width, height = size(pixMap)
|
height, width = size(pixMap)
|
||||||
target = zeros(eltype(pixMap), height, width)
|
target = zeros(eltype(pixMap), height, width)
|
||||||
println("Matrix Dimensions: ", size(pixMap))
|
|
||||||
|
|
||||||
for j in 2:(width-1)
|
for j in 2:(width-1)
|
||||||
for i in 2:(height-1)
|
for i in 2:(height-1)
|
||||||
println("Current Indices: i = $i, j = $j")
|
|
||||||
neighbors = []
|
neighbors = []
|
||||||
for dj in max(1, j-1):min(width, j+1)
|
for dj in max(1, j-1):min(j+1, width)
|
||||||
for di in max(1, i-1):min(height, i+1)
|
for di in max(1, i-1):min(i+1, height)
|
||||||
push!(neighbors, pixMap[di, dj])
|
push!(neighbors, pixMap[di, dj])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
target[i, j] = median(neighbors)
|
target[i, j] = median(neighbors)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return target
|
||||||
return target
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user