Basically, this is an oversimplified illustration that shows exactly what I want. Instead of me selecting each patch individually then apply the gradient I can just use select > color range or magic wand/inverse to make multiple selections and photoshop should automatically fill each selected patch with its own gradient. In this case, the gradient will always be the same. Is there an easy way to do this so I don't have to write a script?
Edited: For those don't know if you select all the patch and apply a gradient you will see the result like the first image.