# RSVQ-Diffusion Model for Text-to-Remote-Sensing Image Generation
## 3 Methods
### Spatial Positional Encoding  
Compared to other encoding mechanisms, spatial positional encoding helps the model better learn the spatial structure and positional relationships within images. Since remote sensing images typically contain complex geographical information and spatial features, spatial positional encoding is particularly important for remote sensing image generation. Due to the Transformer's tendency to overlook the two-dimensional spatial structure during sequence processing, this study improves upon the original positional encoding to develop spatial positional encoding. By combining spatial positional encoding with the positional encoding in the original network, the Transformer is enhanced to better learn the spatial features of remote sensing images. The spatial positional encoding, original positional encoding, and their fusion principle are illustrated in Figure 3. The two-dimensional coordinate information (x, y) of the input image is extracted and encoded through a sinusoidal calculation to obtain the spatial positional encoding. For the original positional encoding, the input image is unfolded into a one-dimensional sequence, and the positional information n of each sequence position is also encoded using a sinusoidal method. Finally, the encodings are fused to obtain the final combined positional encoding.  
First, the calculation process for spatial positional encoding is detailed in Equations (5)-(7).  
\[\left\{\begin{array}{l}SPE_{row}(i,2k)=sin(\frac{i}{H}.2\pi)\\ SPE_{row}(i,2k+1)=cos(\frac{i}{H}.2\pi)\end{array}\right. \tag{5}\]  
where \(H\) represents the height of the image; \(i\) represents the row position index ranging from \(i=0,\ 1,\dots,H-1\); and \(k\) is the embedding dimension index, ranging from \(k=0,\ 1,\dots,\ \frac{D}{Z}-1\) (where \(D\) is the embedding dimension, i.e., the dimension of the position representation).  
\[\left\{\begin{array}{l}SPE_{col}(j,2k)=sin(\frac{j}{w}.2\pi)\\ SPE_{col}(j,2k+1)=cos(\frac{j}{w}.2\pi)\end{array}\right. \tag{6}\]  
Figure 3: Principle of spatial positional encoding.  
where \(W\) represents the width of the image, and \(j\) is the column position index, ranging from \(j=0,\ 1\,\ldots,\ W-1\).  
\[SPE(i,j)=concat(SPE_{raw}(i,j),SPE_{col}(i,j)) \tag{7}\]  
The shape of the spatial positional encoding, \(SPE(i,j)\), is \((B,H+W,D)\), where \(B\) is the batch size.  
Second, the sequential positional encoding calculation of the Transformer architecture is detailed in Equation (8).  
\[\left\{\begin{array}{l}PE(i,2k)=sin(\frac{i}{10000\frac{2\pi}{D}})\\ PE(i,2k+1)=cos(\frac{i}{10000\frac{2\pi+1}{D}})\end{array}\right. \tag{8}\]  
where \(i\) is the position index ranging from \(i=0\), \(1\), \(\ldots\), num_steps-1(where num_steps represents the length of the sequence); and \(k\) is the embedding dimension index, ranging from \(k=0,1,\ldots,\frac{D}{2}-1\). The shape is \((B,\ N,\ D)\) (where \(N\) represents the number of time steps).  
Finally, the two positional encodings are combined during the forward propagation process of the positional encoding, as detailed in Equation (9).  
\[UPE=SPE(i,j)\oplus PE(i) \tag{9}\]  
where \(\oplus\) represents the concatenation of the sinusoidal and spatial positional encodings along the embedding dimension. The final unified positional encoding, \(UPE\), takes the shape of \((B,H+W+N,D)\).