\section{Introduction}
%Storyline: bad data/artifacts => Restoration => unsupervised approach => unsupervised detection and segmentation of artifacts. 
Histopathological analysis stands at the forefront of diagnostic medicine, informing critical decisions with life-altering implications. Yet, the reliability of such analysis is often compromised by artifacts introduced during sample preparation and imaging, ranging from staining inconsistencies~\cite{TELLEZ2019101544} to physical obstructions like folds and blood cells~\cite{kanwal2022devil}. These artifacts can distort the data, leading to diagnostic inaccuracies of the employed AI~\cite{schomig2021quality,wang2021stress}.

While in clinical practice, whole slide images (WSI) can be rescanned to address these issues, the restoration of corrupted histopathological images with an AI model offers an effective alternative to improve image quality without such \textbf{labor and time-consuming} process. Recent methods have ventured into this territory with supervision-heavy approaches, demanding extensive manual input~\cite{he2023artifact} or supervision~\cite{dahan2022artifact,ke2023artifact} on patches containing artifacts in order to restore a WSI. %Such methods, while innovative, fall short in real-world scenarios where unseen artifacts are common and manual intervention is costly. 
Approaches that explicitly learn each artifact type's appearance by supervision will struggle with unseen artifacts and fail to restore the image~\cite{he2023artifact}, especially where unseen artifacts are common and manual intervention is costly. These supervisions usually render such approaches unreliable and labor-intensive when pursuing a holistic pipeline. To the best of our knowledge, there has not been a holistic, unsupervised approach that detects the artifacts and performs image restoration in one pipeline. Recognizing this gap, we introduce a fully unsupervised Histopathological artifact restoration pipeline (HARP) that deploys the three steps depicted in Figure~\ref{fig:pipeline}, which are essential for a clinical workflow for computational pathology: \textbf{artifact detection}, \textbf{artifact  localization}, and \textbf{artifact restoration}.

\begin{figure}[t]
    \centering
    \includegraphics[width=0.8\textwidth]{figures/restoration_pipeline.png}
    \caption{\textbf{Overview of Histological Artifact Restoration Pipeline (HARP)}} 
    \label{fig:pipeline}
\end{figure}

In order to make HARP useable in the clinical workflow, the first step is to reliably detect artifacts. Many studies in recent years have developed unsupervised anomaly detection methods, which are able to identify unusual images~\cite{wang2021student,yu2021fastflow,zavrtanik2021draem}. We evaluate anomaly detection methods with the AnomaLib framework~\cite{akcay2022anomalib} on histopathology images with realistic and proven synthetic artifacts from ~\citet{stieber2022FrOoDo}. %We reuse the implementations from AnomaLib for these methods. 
In the second step, we require the localization of the relevant artifacts. This step is crucial for the applicability of our pipeline to generalize to many different artifact types without requiring knowledge of them. Based on the original image, we generated multiple localization masks of artifacts by leveraging pre-trained knowledge of SAM~\cite{kirillov2023segment} and clustering with DBSCAN~\cite{ester1996density}. As we train a diffusion model to restore the images, we leverage it to generate an activation map, which we deploy to rank the top 5 masks. In the final step, we conduct the artifact restoration. We generate a restored image for each localization by conditioning our diffusion model to inpaint the image based on the localization mask. Recent works~\cite{he2023artifact} have shown great results on artifact inpainting with the RePaint~\cite{lugmayr2022repaint} and manually annotated artifacts. This approach has the limitation of being computationally heavy, rendering it unsuitable for a clinical workflow. HARP leverages our novel inpainting denoising diffusion model, incorporating the condition input at every step, which reduces the required computational time. Lastly, we select the final image with the artifact detection method.
In summary, our contributions are threefold. We evaluated existing anomaly detection methods for histopathological artifacts. Secondly, we develop a \textbf{(I) novel conditional image inpainting denoising diffusion model}. Further, we demonstrate its capability for \textbf{(II) artifact localization and restoration}, and we evaluate the \textbf{(III) impact of HARP on downstream model performance}. Lastly, we evaluate the restored images by conducting a \textbf{(III) study with pathologists}.% to identify restored images.