problem of take out ROI while use Superpixels

1 view (last 30 days)
hajer jon
hajer jon on 23 Oct 2019
Commented: Uma Sharma on 14 Jul 2022
Hi
i wrote code that select ROI then devide image to patches then appaly superpixels but the superpixels results show that non ROI is calcute superpixels on it how can i let not take the non ROI while counting???
I3=read(v,1);
BW = roipoly(I3);
for t=1:4
imca=im2patch{t}
figure;imshow(imca);
t=t+1;
[Lce,N] = superpixels(imca,500);
BWL1 = boundarymask(Lce);
masimg1=imoverlay(imca,BWL1);
figure;imshow(masimg1);
end;roiandsuperpicels.jpg

Answers (1)

Subhadeep Koley
Subhadeep Koley on 10 Jan 2020
Hi, you are getting such output because you are applying super-pixel over segmentation on the whole image. You can use the function roifilt2 to apply your filtering only to the ROI. Refer the code below.
I = imread('peppers.png');
BW = roipoly(I);
imshow(BW);
% Create function handle
f = @(x)superpixels(x,500);
% Apply 2-D superpixel oversegmentation on the ROI
if size(I, 3) == 3
J = roifilt2(rgb2gray(I), BW, f);
else
J = roifilt2(I, BW, f);
end
% Create the mask
mask = boundarymask(J, 8);
% Overlay the mask above the image
figure;imshow(labeloverlay(I, mask, 'Transparency', 0.3, 'Colormap', 'parula'));
SLIC.png
Hope this helps!
  1 Comment
Uma Sharma
Uma Sharma on 14 Jul 2022
Hi,
This response was very helpful! Using the function handle, how can I get the label and numIterations data from the superpixel function for the superpixels in the ROI? Please let me know if there are any solutions to this.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!