Filtering a region of Interest

3 views (last 30 days)
Please I would like some help wih a question, I am trying to apply a filter to a region of interest using the roipoly and roifilt2 function, then show the effect on the original image. The problem is, I have to extract a portion of the image containing a range of pixels, which I managed to do with this:
image = imread('image8.jpg');
imshow(image)
% imModified = blockproc(image,[20 20],@(blkStruct) dct2(blkStruct.data));
% imshow(imModified)
%Select [56:281, 56:281]
Subimage = image(56:281, 221:412);
imshow(Subimage)
Then I was able to select the region of interest with the roipoly function
%Hexagon
c = [60 27 14 78 130 139];
r = [14 38 127 177 160 69];
Hex = roipoly(Subimage,c,r);
figure
imshow(Hex)
Then I applied an averaging filter
%Average filter
C = fspecial('average', [20,20]);
M = roifilt2(C,Subimage,Hex);
then showed the image
%Show images
figure
imshow(M)
I understand up to here, but now I want to show the effect of the filter on the original full image ('image8.jpg') and not the Subimage (from above). Please if anyone could help me I would appreciate it.

Accepted Answer

Robert U
Robert U on 18 Oct 2019
Hi Oreoluwa ADESINA,
What you describe is part of the example shown in the roifilt2-documentation found here: https://de.mathworks.com/help/images/ref/roifilt2.html
You would have to redefine your "c" and "r".
Kind regards,
Robert
  3 Comments
Robert U
Robert U on 20 Oct 2019
Hi Oreoluwa ADESINA,
Since all values defining vertices are pixel based you can shift them around by appropriately adding and subtracting the crop-pixel values.
You cropped your image by
Subimage = image(56:281, 221:412);
thus, all x-pixels are shifted by 56 and y-pixels by 221. In order to apply the same polygon as on the cropped Subimage you would have to add the "offset".
cFull = c + 221;
rFull = r + 56;
HexFull = roipoly(image,cFull,rFull);
MFull = roifilt2(C,image,HexFull);
In order to avoid confusion you probably want to rename your variable "image" due to the fact that image() is a built-in command.
Kind regards,
Robert
Oreoluwa ADESINA
Oreoluwa ADESINA on 22 Oct 2019
Thank you, I understand it clearly now

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!