Lily
Lily

Reputation: 315

applying an image filtering technique on 'selected' pixels in MATLAB

The feature extraction step of my algorithm, applies some filter on a "3D" image and use the value of filtered pixels as the feature of original pixels of image.

My problem is that I need the feature of only small subset of pixels(threshold-ed pixels), not all of the image. and it is time consuming to filter all of the image, instead of only some pixels.

My question is how can I filter only selected pixels of an image? Is there any matlab function for this purpose?(I think I can not use imfilter)

Thank you.

Upvotes: 1

Views: 2937

Answers (2)

pklaus
pklaus

Reputation: 657

Here is a fast matrix operation in Matlab that applies a threshold to the image:

% let's assume i is your image (matrix)
thresh = 60; % set the threshold for pixel values
i = uint16(i > thresh) .* i; % adjust uint16 to your: class(i)

This will set all pixels to 0 which are below the threshold.
If you want to apply the filter to a smaller area afterwards, you can then check which columns and rows of your image contain values larger than zero and crop the image accordingly or define a region of interest using roipoly.

Upvotes: 2

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

Use roifilt2. The following code was taken directly from Matlab Documentation site

I = imread('eight.tif');

First, define the region of interest:

c = [222 272 300 270 221 194];
r = [21 21 75 121 121 75];
BW = roipoly(I,c,r);

In your case, BW is already defined, so you can skip the previous step.

Now, apply the filter:

H = fspecial('unsharp');
J = roifilt2(H,I,BW);
figure, imshow(I), figure, imshow(J)

Upvotes: 4

Related Questions