How to shift array circularly using optimisation algorithm?
2 views (last 30 days)
Show older comments
I have sensor data and the sensor location. Using these data, I have applied an algorithm for generating a 3D volume and computing the contrast of the images. However, because of some delay, the sensor data are misplaced. Now, I want to apply an optimization algorithm or iterative algorithm which help to shift the sensor data in right place and provide a better contrast value. I wish to use contrast value or function as an objective function for the optimization algorithm. And if the algorithm reaches maximum contrast values, it stops.
Thanks in advance for helping me.
0 Comments
Answers (1)
William Rose
on 13 Jun 2022
Here is a script that demonstrates how you can find the best shift of a 3D array. In this script, I generate a 3D array which contains a 3D Gaussian function. The Gaussin is centered initially. The figure of merit, which is minimized when the Gaussian is centered within the 3D array, is the sum of the elements on the outside faces of the 3D array. I hope you can imagine that if the Gaussian is centered, then the sum of the elements on the outside faces will be as low as it can be. I compute and display the sum, using function sumPerim(). Then I circularly shift the 3D array by an arbitrary amount along the x, y, and z axes - different amount of shift for each axis. Then I compute and display the sumPerim() for the shifted array. sumPerim() is higher for the shifted array than for the unshifted array, as expected.
Now I pretend that I don't know how much I shifted the 3D array by. I search for the amount of shift along each axis (independently) that will minimize sumPerim(). Then I apply those shifts along z, y, and x. Then I compute and display the sumPerim() of the doubly-shifted array. sumPerim() of the doubly-shifted array matches the sumPerim() of the original array. This shows that I have successfully rotated the array back to its original position.
You can use a similar strategy for your 3D array. In your case, the figure of merit, wihcih you want to maximize, is contrast for the image.
I compute the shift for each axis independently. Then I apply the shift to Z, then Y, then X. You could apply the shift in the order Y,X,Z or X,Z,Y, or X,Y,Z, or Y,Z,X, or Z,X,Y: six possible orderings. You could try all six possible orderings, and choose whichever one gives the greatest contrast.
In this particular example, the dimensions of the 3D array are 10x11x12. The initial shift is 3,5,2 along x,y,z respectively. The "best shift" which minimizes sumPerim(), is 7,6,10 along x,y,z respectively. This makes sense, because if you add the initial shift to the best shift, you get 3+7, 5+6, 2+10 = 10,11,12. Those are the array dimensions. That means you have rotated the array back to where it started, since the shifting is circular.
Good luck.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!