Filtering a region of Interest

2 ビュー (過去 30 日間)
Oreoluwa ADESINA
Oreoluwa ADESINA 2019 年 10 月 18 日
コメント済み: Oreoluwa ADESINA 2019 年 10 月 22 日
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.

採用された回答

Robert U
Robert U 2019 年 10 月 18 日
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 件のコメント
Robert U
Robert U 2019 年 10 月 20 日
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 2019 年 10 月 22 日
Thank you, I understand it clearly now

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by