Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB


Steve on Image Processing with MATLAB has been archived and will not be updated.

Find all the highest pixel values using ismember

Today's post shows how to use ismember to conveniently locate all of the highest pixel values in an image. For example, in the following Hough transform image, what are the 20 highest values, and where are all the pixels that have those values?
I got the idea from some example code written by Image Processing Toolbox writer Megan Mancuso. Megan says she got the idea to use ismember this way from Ahmed's answer on MATLAB Answers.
Here's where the Hough transform image above comes from.
A = imread("gantrycrane.png");
bw = edge(rgb2gray(A),"canny");
[H,T,R] = hough(bw);
daspect auto
axis on
Now let's sort to figure out the highest 20 values of H.
sorted_H_values = sort(H(:),"descend");
highest_H_values = sorted_H_values(1:20)
highest_H_values = 20×1
293 250 209 205 182 177 173 172 171 168
Finally, I'll use ismember to compute a binary image showing all the elements of H that have one of those 20 highest values. (And I'll use xlim and ylim to zoom in so that we can see a few of those elements clearly.)
mask_20_highest_values = ismember(H,highest_H_values);
daspect auto
axis on
xlim([-10 60])
ylim([141 452])
Any element-wise logical function, such as ismember, can be used in this way to produce a binary image. So add this to your bag of MATLAB tricks!
  • print


要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。