median filter border fix, files get renamed if they don't have correct extension

This commit is contained in:
Pixelguy14 2025-03-09 14:02:53 -06:00
parent 421d594b99
commit 8e1c473acb
2 changed files with 60 additions and 18 deletions

50
app.jl
View File

@ -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
using Base.Filesystem: mv # To rename files in the system
include("./julia_imzML_visual.jl") include("./julia_imzML_visual.jl")
@genietools @genietools
@ -248,8 +249,34 @@ include("./julia_imzML_visual.jl")
# The onbutton handler will set the variable to false after the block is executed # The onbutton handler will set the variable to false after the block is executed
@onbutton btnSearch begin @onbutton btnSearch begin
full_route=pick_file(; filterlist="imzML,mzML") full_route=pick_file(; filterlist="imzML,imzml,mzML,mzml")
msg="" msg=""
if full_route != ""
if endswith(full_route, "imzml")
alt_route=replace(full_route, r"\.[^.]*$" => ".imzML")
mv(full_route, alt_route)
full_route=alt_route
# to detect if there's an mzml named wrong
alt_routeMz=replace(full_route, r"\.[^.]*$" => ".mzml")
if isfile(alt_routeMz)
alt_routeMz2=replace(alt_routeMz, r"\.[^.]*$" => ".mzML")
mv(alt_routeMz, alt_routeMz2)
alt_routeMz=alt_routeMz2
end
end
if endswith(full_route, "mzml")
alt_route=replace(full_route, r"\.[^.]*$" => ".mzML")
mv(full_route, alt_route)
full_route = alt_route
# to detect if there's an imzml named wrong
alt_routeMz=replace(full_route, r"\.[^.]*$" => ".imzml")
if isfile(alt_routeMz)
alt_routeMz2=replace(alt_routeMz, r"\.[^.]*$" => ".imzML")
mv(alt_routeMz, alt_routeMz2)
alt_routeMz=alt_routeMz2
end
end
end
if full_route=="" if full_route==""
msg="No file selected" msg="No file selected"
warning_msg=true warning_msg=true
@ -283,7 +310,7 @@ include("./julia_imzML_visual.jl")
eTime=round(fTime-sTime,digits=3) eTime=round(fTime-sTime,digits=3)
msg="Plot loaded in $(eTime) seconds" msg="Plot loaded in $(eTime) seconds"
else else
# If there's no MzML file, we deny access again # If there's no mzML file, we deny access again
btnSpectraDisable=true btnSpectraDisable=true
SpectraEnabled=false SpectraEnabled=false
end end
@ -291,17 +318,6 @@ include("./julia_imzML_visual.jl")
full_routeMz=full_route full_routeMz=full_route
btnSpectraDisable=false btnSpectraDisable=false
SpectraEnabled=true SpectraEnabled=true
# Splitting the route the same way
full_route=replace(full_route, r"\.[^.]*$" => ".imzML")
if isfile(full_route)
btnStartDisable=false
else
btnStartDisable=true
full_route=full_routeMz
end
if endswith(full_route, "imzML")
btnStartDisable=false
end
if isfile(full_routeMz) if isfile(full_routeMz)
# Start the sum spectrum creation on loading # Start the sum spectrum creation on loading
progressSpectraPlot=true progressSpectraPlot=true
@ -322,6 +338,14 @@ include("./julia_imzML_visual.jl")
eTime=round(fTime-sTime,digits=3) eTime=round(fTime-sTime,digits=3)
msg="Plot loaded in $(eTime) seconds" msg="Plot loaded in $(eTime) seconds"
end end
# Splitting the route the same way
full_route=replace(full_route, r"\.[^.]*$" => ".imzML")
if isfile(full_route)
btnStartDisable=false
else
btnStartDisable=true
full_route=full_routeMz
end
end end
xCoord=0 xCoord=0
yCoord=0 yCoord=0

View File

@ -409,21 +409,39 @@ end
# 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)
height, width = size(pixMap) height, width = size(pixMap)
padded_pixMap = padarray(pixMap, 1)
target = zeros(eltype(pixMap), height, width) target = zeros(eltype(pixMap), height, width)
for j in 2:(width-1)
for i in 2:(height-1) for j in 1:width
for i in 1:height
neighbors = [] neighbors = []
for dj in max(1, j-1):min(j+1, width) for dj in j:j+2
for di in max(1, i-1):min(i+1, height) for di in i:i+2
push!(neighbors, pixMap[di, dj]) push!(neighbors, padded_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
function padarray(A, padsize)
h, w = size(A)
padded = zeros(eltype(A), h + 2*padsize, w + 2*padsize)
padded[padsize+1:end-padsize, padsize+1:end-padsize] .= A
padded[1:padsize, padsize+1:end-padsize] .= A[1:padsize, :]
padded[end-padsize+1:end, padsize+1:end-padsize] .= A[end-padsize+1:end, :]
padded[padsize+1:end-padsize, 1:padsize] .= A[:, 1:padsize]
padded[padsize+1:end-padsize, end-padsize+1:end] .= A[:, end-padsize+1:end]
padded[1:padsize, 1:padsize] .= A[1, 1]
padded[1:padsize, end-padsize+1:end] .= A[1, end]
padded[end-padsize+1:end, 1:padsize] .= A[end, 1]
padded[end-padsize+1:end, end-padsize+1:end] .= A[end, end]
return padded
end
# sumSpectrumPlot recieves the local directory of the image as a string, # sumSpectrumPlot recieves the local directory of the image as a string,
# returns the layout and data for the surface plotly plot # returns the layout and data for the surface plotly plot
# this function loads the spectra data and makes a mean to display # this function loads the spectra data and makes a mean to display