Spatial Diffusion for Cell Layout Generation
Chen Li Xiaoling Hu Shahira Abousamra Meilong Xu Chao Chen


























C. Li et al.



Stony Brook University, Stony Brook, NY, USA Harvard Medical School, Boston, MA, USA




Spatial Diffusion for Cell Layout Generation
    Chen LiEmail: li.chen.8@stonybrook.edu.1 Xiaoling Hu2 Shahira Abousamra1 Meilong Xu1 Chao Chen1

    September 9, 2024
====================================================================================================




§ ABSTRACT 
Generative models, such as GANs and diffusion models, have been used to augment training sets and boost performances in different tasks. We focus on generative models for cell detection instead, i.e., locating and classifying cells in given pathology images. One important information that has been largely overlooked is the spatial patterns of the cells. In this paper, we propose a spatial-pattern-guided generative model for cell layout generation. Specifically, a novel diffusion model guided by spatial features and generates realistic cell layouts has been proposed. We explore different density models as spatial features for the diffusion model. In downstream tasks, we show that the generated cell layouts can be used to guide the generation of high-quality pathology images. Augmenting with these images can significantly boost the performance of SOTA cell detection methods. The code is available at <https://github.com/superlc1995/Diffusion-cell>.






§ INTRODUCTION

Cell detection focuses on identifying and locating multiple types of cells in images or videos. Although deep models have achieved great success in cell detection tasks <cit.>, their deployment in the real world is largely constrained due to the demand for large amounts of labeled training data. 
Collecting and annotating cell detection datasets is high-cost.

Despite the rich literature on the generative model, its application in cell detection is still limited. Although GAN or diffusion models can generate high-quality images with a single or a small number of objects, these models cannot generate images with hundreds or thousands of cells. The primary issue is the lack of an explicit modeling of cell spatial distributions. Numerous factors, including cell-cell interactions, morphogenesis, and cellular functions, make the cells follow a specific spatial pattern <cit.>. 
If a generative model cannot learn these spatial distributions, it will not be able to generate realistic images for data augmentation purposes.
This issue, however, has been largely overlooked by existing generative models. Most existing methods either generate object layouts randomly <cit.> or use existing layouts directly <cit.>. 

Another constraint for layout generation is the backbone methods. Generative adversarial network (GAN) <cit.> cannot handle the large amount of densely packed cells. 
Recent years have witnessed the rise of the diffusion model <cit.>. Diffusion models outperform GANs in image generation <cit.>, and have shown great potential in many other tasks.
The diffusion model's ability to generate realistic images with fine details makes it ideal for layout generation. 

We propose a spatial-distribution-guided diffusion model for cell layout generation.
Our diffusion model learns to generate binary masks, in which each cell is represented by a square marker. 
To incorporate the spatial distribution into the diffusion model, we propose two major ideas. First, to handle the large variation of sparse/dense layouts, we propose to condition the diffusion model on the number of cells. 

Second, we incorporate spatial distributions into the model. Due to the heterogeneity of spatial distribution, it is unrealistic to simply condition the generation on summary statistics of the spatial density. Instead, we design the model to jointly generate both the layout map and the spatial density maps simultaneously. This way, the model will gradually learn the density distribution through the diffusion process.

As another contribution, we explore and analyze different density distribution models for layout generation: (1) Kernel density estimation (KDE); (2) Gaussian mixture model (GMM); and (3) Gaussian Mixture Copula Model (GMCM) <cit.>. While KDE is more flexible, GMM is more constrained and is less likely to overfit. GMCM is a compromise between the two. Our experiments provide a comprehensive analysis of the strengths and weaknesses of the three density models.
Finally, we introduce metric spatial-FID, to evaluate the quality of generated object layouts. The metric maps the generated layouts into a spatial representation space and compares them with the spatial representation of real layouts. This provides an appropriate evaluation metric for cell layouts. 

In experiments, we verify the effectiveness of our method through spatial-FID.
Furthermore, we show that the generated layouts can guide diffusion models to generate high quality pathology images. These synthetic images can be utilized as an augmentation to boost the performance of supervised cell detection methods. 



§ RELATED WORK

Diffusion Model.
Diffusion models generate samples from random noise by learning to eliminate the noise in a multi-stage process <cit.>. Diffusion models are gaining attention because of their superior generation performance compared to GAN models <cit.>.

There are extensive applications of diffusion models: semantic segmentation <cit.>, point cloud generation <cit.>, and video generation <cit.>. Saharia et al. <cit.> propose the super-resolution method SR3 by conditioning the diffusion model on low-resolution images. Dhariwal et al. <cit.> boost the quality of conditional generation for the diffusion model by using classifier guidance. 

Zhu et al. <cit.> apply the diffusion model to align the crowd distribution for various domains. Unlike previous works, we focus on the cell layout and pathology image generation for cell detection. 


Layout Generation.
Layout generation is the task of synthesizing the arrangement of elements. Generative model based methods <cit.> are widely used in this field. LayoutGAN <cit.> and LayoutVAE <cit.> represent pioneering efforts in employing GAN and VAE to generate graphic and scene layouts. LayoutDM <cit.> explores the diffusion based model's capability in layout generation. The works above need access to geometric parameters (location and size) of objects in training layouts. However, only the center coordinates of cells are available for cell detection layouts. TMCCG <cit.> attempts to generate cell layouts with GAN. Considering the superiority of the diffusion model in various generation tasks, we construct a diffusion model based cell layout generation framework. 








§ METHOD

It is essential to generate realistic pathology images for cell detection tasks, and one challenge is to properly model the spatial distribution of these cell layouts. This paper explores multiple ways to summarize the spatial context in cell layouts. By incorporating spatial information in the training process, diffusion models can learn the underlying distribution of cells and generate realistic layouts. We represent the cells in pathology images as a series of 3×3 square markers in layout maps. The markers are in the center of cells. Using narrow markers can prevent layout maps of highly dense cells from collapsing into a big mass. The generated layouts can guide the generation of realistic pathology images.



 §.§ Layout and Image Generation

In this part, we start by explaining our approach to training spatial-aware diffusion models to generate realistic cell layouts. Next, we introduce the diffusion framework for generating synthetic pathology images under the guidance of generated layouts. 

Diffusion Model.

Given data _0   q(_0), the forward diffusion process of diffusion models corrupts original data _0 into _T by introducing Gaussian noise with variance schedule β_1,…,β_T. This process is depicted as a Markov chain formulated as follows: 


    q(_1,…,_T|_t-1) := ∏^T_t=1q(_t|_t-1) 
    
        q(_t|_t-1) := 𝒩(_t; √(1-β_t)_t-1, β_t I )






If T is large enough, the corrupted data _T will nearly follow an isotropic normal distribution. 

The diffusion models sample data from q(_0) by reverse of the diffusion process. The generative process q(_t-1|_t) is approximated by a neural network:


    p_θ(_t-1 | _t) = 𝒩(_t-1; μ_θ(_t, t), σ^2_t I ) 
    μ_θ(_t, t)  =  1/√(α_t) (_t - 1-α_t/√(1- α_t)ϵ_θ(_t, t)  )

where ϵ_θ(x_t,t) is infered by a denoising neural network. Both ϵ_θ(x_t,t) and σ_t are learned by optimizing a hybrid learning objective <cit.>. 







Due to the sparsity of cell layout maps, it is challenging for diffusion models to learn the underlying distribution of cells from the standard training process. To address this problem, we introduce spatial density maps. By modeling the spatial information in a dense way, the spatial density maps teach the model the spatial distribution behind cell layouts. The bond between layout maps and 

density maps assures the generated cell layouts follow the 
spatial distribution of the training set. To incorporate the spatial density map into the training process efficiently, we construct _0 by concatenating cell layout map _0^p and spatial density maps _0^d together: _0 = concat(_0^p, _0^d). We construct _0^p and _0^d by combining the cell layouts and spatial density maps of different cell types. We generate spatial density maps for each cell type independently. As shown in Fig. <ref>, the generated cell layouts are distributed in the corresponding spatial density generation pattern. More samples are available in the supplementary. 

The spatial distribution of cells in pathology images is influenced by density. To make the generation model realize this correlation, we incorporate cell counting in the image patch as prior information for layout generation. However, due to the lack of samples for each quantity, using cell counting as a condition directly will lead to poor-quality layout generation. Here, we split the training image patches by the number of cells in each patch. We define C as the cell count distribution of the training set, and C_p is the p-th quantile of this distribution. We can divide the cell counting space into K ∈ℕ^* parts: [C_i/K, C_(i+1)/K], i∈{0… K-1}. During training, we treat the layouts belonging to the part i as a counting category e_i and condition the diffusion model on these counting categories. In the inference stage, we sample the same number of layouts from each counting category so that the generated layouts share the same counting distribution as the original data. An overview of layout generation and learning process is in Fig. <ref>.

We generate pathology images I using a diffusion model conditioned on the generated layouts. The layout maps _g^p are fed into the denoising neural network as a condition to guide the cell distribution of the generated pathology image. Our layout conditional diffusion model p(I |_g^p) generates pathology images with the layout map _g^p through the neural network approximated denoising process p_w(I_t-1|I_t, x_g^p), where w is the parameter of neural network for pathology image generation. An illustration is shown in Fig. <ref>.

Given the generated high-quality pathology images and their cell layouts, we can augment the existing cell detection methods for better performance. 

 



 §.§ Spatial Feature Extractors

An excellent spatial feature extractor should be able to capture the cluster patterns in cell layouts, including the position, density, and area of cell clusters, which is a challenging task. Here, we present three different ways to extract spatial features: Kernel density estimation (KDE), Gaussian Mixture Model (GMM) <cit.>, and Gaussian Mixture Copula Model (GMCM) <cit.>. 

Kernel density estimation is a non-parametric probability estimation framework, which is widely used for point pattern analysis. Intuitively, KDE treats training data points as density sources, and the combination of effects from training data points will create a smoothed estimate of probability distribution. For each estimating location, the closer data points have higher density contributions. The bandwidth is a crucial parameter for KDE. A lower bandwidth results in an estimation with more details but potentially introduces extra noise. On the other hand, a larger bandwidth produces a smoother result with the risk of oversmoothing. Here, to reach a good balance, we use Scott’s Rule to select bandwidth <cit.>. 

Unlike KDE, the Gaussian mixture is a parametric model, modeling the distributions of object cluster patterns as Gaussian distributions. Therefore, GMM has better interpretability with limited parameters. Here, we introduce another parametric model – the Gaussian mixture copula model (GMCM). The copula function is used to capture the dependency between marginal densities. GMCM uses GMM to estimate the marginal distribution of point cloud and Gaussian mixture copula function, derived from a mixture of Gaussians, to capture the marginal dependency. Due to the non-identifiability nature of the components in GMCM and GMM, we adopt an EM algorithm <cit.> to optimize the parameters of GMCM and GMM. Bayesian Information Criterion (BIC) decides the optimal number of components for both GMM and GMCM.





































































§ EXPERIMENT


We evaluate the effectiveness of cell layout and pathology image generation frameworks. We propose spatial-FID as a Fréchet Inception Distance (FID) modification to measure the quality of generated cell layouts. We also evaluate the effectiveness of our layout conditional pathology image generation framework on cell detection tasks. 


Datasets. We evaluate our methods on cell detection dataset BRCA-M2C <cit.>. BRCA-M2C has 80, 10, and 30 pathology image patches for training, validating, and testing, respectively. This dataset has three cell types: tumor, lymphocyte, and stromal. 



Implementation details.
We separate the training set into five counting categories. To ensure the image patches for training have abundant spatial structures to learn, we crop 464 × 464 patches from whole training images for training diffusion models on BRCA-M2C. The diffusion model of layout generation is a U-Net architecture <cit.> with multiple attention heads at resolution: 32× 32, 16 × 16, and 8× 8. For the image generation framework, we initialize the model with weights from pre-trained super-resolution diffusion model <cit.>. 

For cell detection tasks, we use the state-of-the-art methods MCSpatNet <cit.> and U-Net <cit.> as the cell detection frameworks.















Evaluation metric.
To evaluate the quality of generated layout maps, we propose spatial-FID (↓)[The lower the better.]. The FID is used to measure the performance of the generative model on natural image datasets, e.g., ImageNet and CIFAR-10/100. It thus relies on the visual features from a pre-trained inception model. However, there is a significant difference between natural images and layout maps. Therefore, we train an autoencoder (Fully Convolutional Networks) on the layout maps from the training set to capture the spatial information in the layouts. We use the spatial feature from the middle of the encoder (f_s(·)) to replace the visual features. 
Moreover, introduce spatial-FID formed as follows:


    s^2(( μ_T, Σ_T), (μ_D, Σ_D)) = 
        
    μ_T - μ_D _2^2 +Tr(Σ_T + Σ_D - 2( Σ_TΣ_D)^(1/2))

where μ_T (μ_D) and Σ_T (Σ_D) are the mean and covariance of the spatial features extracted by f_s(·) from training layouts (generated layouts), respectively. 

We use F-scores to evaluate the cell detection performance.



 
















 §.§ Results

In this part, we train the model on the training set, generate 200 layouts with corresponding pathology images for each counting category, and evaluate our method from layout generation and cell detection augmentation.

As shown in Tab. <ref>, the spatial density map generated by GMM achieved the best performance due to the distribution of cells in BRCA-M2C conforming to the mixture of Gaussian best. The cell layout distribution of BRCA-M2C data has distinct subgroups or clusters, and GMM can effectively capture these patterns. The flexibility of KDE leads to noisy density estimation results in our case, preventing our framework from getting better layout generation. GMCM models dependencies between variables using copulas, which can introduce additional complexity. The mismatches between GMCM's assumption and data distribution lead to inferior layout generations.

According to Tab. <ref>, the pathology image generations directed by GMM boost the cell detection performance best, reflecting that better cell layouts lead to higher-quality pathology image generations. As shown in Fig. <ref>, our pathology image generations are deceptively realistic. 

This is mainly attributed to high-quality cell layout generations and the excellent performance of diffusion models in pathology image generation.






 §.§ Ablation study

We conduct ablation studies to show each component's effectiveness and the effects of hyper-parameters on the generation framework. The supplementary includes more ablation studies.

Counting categories.
We conduct ablation studies by discarding this condition or setting different numbers of counting categories (10 or 20) to show the effectiveness of counting categories in cell layout generation. According to Tab. <ref>, counting categories are important for generating realistic cell layouts, and our method is robust to the change of counting categories. 





























































































§ CONCLUSION

In this paper, we propose a spatial-distribution-guided diffusion framework for generating high-quality cell layouts and pathology images. 
To represent the spatial distribution of cell layouts properly, we explore three alternative tools for spatial feature extraction: KDE, GMM, and GMCM. 
They all can significantly boost the generative quality of cell layouts. Due to the underlying cell layouts of BRCA-M2C complying with the mixture of Gaussian best, GMM achieves the best performance. 
We treat generated cell layouts as conditions for pathology image generation. 
These high-quality generated pathology images can improve the performance of SOTA cell detection methods.



§ SUPPLEMENTARY




 §.§ Ablation study



  §.§.§ Bandwidth.

A good bandwidth selection is critical for the quality of spatial information represented by KDE. Here, we study the effect of bandwidth using constant values. As shown in Tab.<ref>, the Scott method is more valid for extracting spatial information from cell layouts.







  §.§.§ Number of components


As we show in Tab. <ref>, selecting the component number of GMM by BIC is essential for generating high-quality spatial density maps by GMM.






 §.§ Samples


Here, we show more generated layouts, corresponding generated pathology images, and density maps. As shown in Fig. <ref>, the density map can reflect the spatial distribution of cells well.



Acknowledgements: This research was partially supported by the National Science Foundation (NSF) grant CCF-2144901, the National Institute of General Medical Sciences (NIGMS) grant R01GM148970, and the Stony Brook Trustees Faculty Award.

Disclosure of Interests: The authors have no competing interests to declare that are relevant to the content of this article.


































































































































splncs04

