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