Sunday, July 21, 2024
HomeMatlabPeaks, Peak Filtering, and Grey-Scale Weighted Centroids » Steve on Picture Processing...

Peaks, Peak Filtering, and Grey-Scale Weighted Centroids » Steve on Picture Processing with MATLAB


Right now, I am persevering with my current theme of desirous about peak-finding in pictures. Once I wrote the primary one (19-Aug-2021), I did not understand it was going to show right into a collection. This could be the final one—however no guarantees!
My earlier submit (17-Sep-2021) was based mostly on 1-D examples. Right now’s submit focuses on a picture instance (in 2-D), and it connects to utilizing regionprops to compute gray-weighted centroids of peaks. I will additionally throw in some 3-D floor visualization, only for enjoyable. Right here is right now’s picture:

url = “https://blogs.mathworks.com/steve/information/snowflakes2.png”;

imshow(A)

I would wish to see if we are able to focus algorithmically on these white blobby issues (that is a technical time period that I discovered in engineering college). First, let’s attempt computing the regional maxima.

A_regmax = imregionalmax(A);

imshow(A_regmax)

At first look, that does not seem like what I am after. Let’s discover out what is going on on right here.

A_regmax_overlay = imoverlay(A,A_regmax,“inexperienced”);

imshow(A_regmax_overlay)

I need to look carefully at one white blobby factor specifically.

imshow(A_regmax_overlay(30:47,263:285,:))

One, or possibly two, of those areas seems just like the form of peak that we’re taken with. What in regards to the others? Let me present you two other ways to discover additional. The primary is with a 3-D visualization, the place we deal with the picture pixel values as heights of a grey floor. The code under reveals that floor, after which it shows the detected regional maxima as blue-and-yellow dots simply above the floor.

A_cropped = A(30:47,263:285);

A_regmax_cropped = A_regmax(30:47,263:285);

surf(A_cropped, EdgeColor = “none”)

[y,x,~] = discover(A_regmax_cropped);

z = A_cropped(A_regmax_cropped);

plot3(x,y,z+1,LineStyle=“none”,Marker=“o”,

set(gca,YDir = “reverse”)

maintain off

A second method is to return to 2-D, however utilizing an especially zoomed-in view, with the precise pixel values superimposed on the person pixels. To perform, I used the Picture Viewer and the Pixel Area Instrument. Under is a display screen shot of the Pixel Area Instrument. I’ve annotated the display screen shot with the areas of the regional maxima.

With both approach, you will get the concept a number of of those maxima areas are simply small, uninteresting fluctuations.

As I mentioned within the earlier posts, you should use the h-maxima rework to filter out these small peaks.

imshow(B(30:47,263:285))

B_regmax = imregionalmax(B);

imshow(B_regmax(30:47,263:285))

B_regmax_overlay = imoverlay(B,B_regmax,“inexperienced”);

imshow(B_regmax_overlay)

axis([225 315 30 60])

I need to end up with a connection to the regionprops operate. This operate is used most frequently with a binary picture enter, and it computes varied geometries properties of objects (related parts) within the binary picture. However you may also present a gray-scale picture on the identical time. With that additional information, you’ll be able to compute different properties. Right here, I’m within the weighted centroids of the varied detected peaks. The unique picture pixel values will likely be used because the weights. This is how one can do it:

props = regionprops(“desk”,B_regmax,A,“WeightedCentroid”)

And this is one approach to visualize the outcomes:

plot(props.WeightedCentroid(:,1),props.WeightedCentroid(:,2),

LineStyle=“none”, Marker=“o”, MarkerEdgeColor=“y”,

maintain off

title(“Grey-scale weighted centroids”)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments