In this paper, we propose a color image compression and encryption algorithm that combines compressed sensing, Sudoku matrix, and hyperchaotic map to ensure the security of image data and improve transmission and storage efficiency. Firstly, we design a novel two-dimensional sine-logistic coupled hyperchaotic map that exhibits a more continuous and broader chaotic range and more complex hyperchaotic behavior compared to some existing known chaotic maps. Secondly, to mitigate the impact of compression thresholds on image reconstruction quality, we employ multiple optimization strategies to improve the dung beetle optimization algorithm, enhancing its global exploration and local exploitation capabilities, thereby making it more efficient and accurate in handling complex optimization problems. Based on this, we optimize the compression threshold using the improved algorithm to find the optimal threshold for the best image reconstruction quality. Finally, to further enhance the security of the algorithm, we introduce Sudoku matrices in the permutation stage. By using randomly generated Sudoku matrices to permute the image pixel positions, the original image structure is effectively disrupted, increasing the complexity and randomness of the encryption. In the diffusion stage, we employ a bidirectional diffusion operation to ensure that pixel information is effectively spread throughout the image, and we dynamically update the diffusion keys in each round, making the key sequence highly random and unpredictable. Experimental results demonstrate that the proposed algorithm can resist various illegal attacks and offers high security.