Image and Video Watermarking Algorithm Using Optimization Techniques