From 8e1c473acbdb74d02af8022efb55e9f71248069c Mon Sep 17 00:00:00 2001 From: Pixelguy14 Date: Sun, 9 Mar 2025 14:02:53 -0600 Subject: [PATCH] median filter border fix, files get renamed if they don't have correct extension --- app.jl | 50 ++++++++++++++++++++++++++++++++----------- julia_imzML_visual.jl | 28 +++++++++++++++++++----- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/app.jl b/app.jl index beaa226..9c0255f 100644 --- a/app.jl +++ b/app.jl @@ -13,6 +13,7 @@ using Images using LinearAlgebra using NativeFileDialog # Opens the file explorer depending on the OS using StipplePlotly +using Base.Filesystem: mv # To rename files in the system include("./julia_imzML_visual.jl") @genietools @@ -248,8 +249,34 @@ include("./julia_imzML_visual.jl") # The onbutton handler will set the variable to false after the block is executed @onbutton btnSearch begin - full_route=pick_file(; filterlist="imzML,mzML") + full_route=pick_file(; filterlist="imzML,imzml,mzML,mzml") 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=="" msg="No file selected" warning_msg=true @@ -283,7 +310,7 @@ include("./julia_imzML_visual.jl") eTime=round(fTime-sTime,digits=3) msg="Plot loaded in $(eTime) seconds" else - # If there's no MzML file, we deny access again + # If there's no mzML file, we deny access again btnSpectraDisable=true SpectraEnabled=false end @@ -291,17 +318,6 @@ include("./julia_imzML_visual.jl") full_routeMz=full_route btnSpectraDisable=false 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) # Start the sum spectrum creation on loading progressSpectraPlot=true @@ -322,6 +338,14 @@ include("./julia_imzML_visual.jl") eTime=round(fTime-sTime,digits=3) msg="Plot loaded in $(eTime) seconds" 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 xCoord=0 yCoord=0 diff --git a/julia_imzML_visual.jl b/julia_imzML_visual.jl index 7c5add6..2316c25 100644 --- a/julia_imzML_visual.jl +++ b/julia_imzML_visual.jl @@ -409,21 +409,39 @@ end # This one in particular is a midpoint fiter from a 3x3 neighbour area function medianFilterjl(pixMap) height, width = size(pixMap) + padded_pixMap = padarray(pixMap, 1) 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 = [] - for dj in max(1, j-1):min(j+1, width) - for di in max(1, i-1):min(i+1, height) - push!(neighbors, pixMap[di, dj]) + for dj in j:j+2 + for di in i:i+2 + push!(neighbors, padded_pixMap[di, dj]) end end target[i, j] = median(neighbors) end end + return target 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, # returns the layout and data for the surface plotly plot # this function loads the spectra data and makes a mean to display