An equivalent function to "imregionalmax" with higher speed
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
moh mor
el 13 de En. de 2024
Hello, I have to find the second biggest peak value of a number of 2D array. One way is to iterate over all of these arrays and perform "imregionalmax" to each one and find the second biggest peak. The problem that I am facing with, is that the number of these 2D arrays are a lot and "imregionalmax" is low-speed. (I need to implement this algorithm thousands of times and therefore, its speed is a critical issue.) So, I'm eager to know if there is any replacement for above method? Thank you
2 comentarios
Image Analyst
el 13 de En. de 2024
What is your definition of " second biggest peak value" for a 2-D array? The area of it? The gray level at the very peak?
imregionalmax will only give a single pixel at the brightest point -- it will not give you the entire peak out to where a valley is encountered and it begins to turn upwards again.
Are you sure that doing it slice by slice on the 2-D slices will give you the correct peak as if you considered the 3-D array as a whole?
DGM
el 14 de En. de 2024
Editada: DGM
el 14 de En. de 2024
imregionalmax() will give the entire connected region of maximal value. The only case in which the region is a single pixel is when a single pixel is surrounded by smaller values.
It's hard to suggest an alternative without knowing the requirements, but bear in mind that imregionalmax() does what imregionalmax() needs to do. It's lean and written in MEX already and actually has a method for gpuarrays. You're probably going to have a hard time trying to write anything in assorted m-code that can beat it, unless you actually need something other than what imregionalmax() does.
As to the ambiguity of "second biggest peak value", bear in mind that the regional max with the second-highest value is not necessarily the apex of the region it encloses. The blog post I linked to below shows an example where it's not. I don't know if that matters to you.
Respuesta aceptada
Matt J
el 14 de En. de 2024
Editada: Matt J
el 14 de En. de 2024
If you can count on the "peaks" to be a single pixel in size, you can just do,
ispeak=A>=imdilate(A,ones(3)); %A is the image
2 comentarios
DGM
el 14 de En. de 2024
I was looking for this earlier:
Más respuestas (1)
Hassaan
el 13 de En. de 2024
- Parallel Processing: If you have multiple cores available, you can use MATLAB's parallel processing tools (parfor loop or batch processing) to process multiple arrays simultaneously. This can significantly speed up the computation.
- Optimized Search Algorithm: Instead of using imregionalmax, you can write a custom function that is optimized for your specific data. For example, if your data has certain characteristics (like sparsity or known range of peak values), you can tailor your search algorithm to leverage these.
- Downsampling: If the arrays are large, consider downsampling them to reduce the amount of data to process. This is effective if the peaks are still discernible in the lower-resolution data.
- Pre-Filtering: Apply a filter to remove noise or smooth the data, which might make the peaks more pronounced and easier to detect. Be cautious with filtering as it can also distort the data.
- Algorithm Refinement: Instead of finding all regional maxima, you might directly search for the top two peaks. This can be done by scanning the array and keeping track of the highest and second-highest values found so far.
- Utilize Built-in Functions for Peak Finding: MATLAB's findpeaks function can be used directly on 2D data by converting the 2D array to a 1D array (either by rows or columns). This might be faster than imregionalmax in some cases.
- Caching Results: If some of the 2D arrays are repeated in the dataset, you can cache the results of the peak-finding process to avoid redundant computations.
- Reducing Precision: If you're working with high-precision data types (like double), consider reducing the precision to single. This can decrease memory usage and potentially speed up calculations, but it might affect the accuracy of the results.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!