# make objects the same class as those around them

2 visualizzazioni (ultimi 30 giorni)
Zohra Megnounif il 4 Apr 2022
Risposto: Chandra il 7 Apr 2022
hello everyone,
I have an image with many cathegorical objects.
I want to transform the blue objects which are "surrounded" by the orange objects of the same category as the orange objects. (only if there ara surrounded by orange objects)
Please How Can I do That ?
##### 4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Zohra Megnounif il 4 Apr 2022
I want to do something like this: if the object (light blue) is surrounded by an orange object, I consider it an orange object
Steven Lord il 4 Apr 2022
Define "surrounded". The upper-left blue object does not appear to touch any of the orange objects and there is a line that you can draw from the blue line (directly towards the left side of the image) that doesn't touch any of the orange objects. So why do you consider it to be surrounded?

Accedi per commentare.

### Risposte (1)

Chandra il 7 Apr 2022
Hi,
Objects of blue colour surrounded by the objects of orange are to be classified into orange objects
Classifying the objects using the colour, by separating the objects into different image and then combining based on the surrounding objects
%Obtaining the image with only orange class(which is similar to red)
B = zeros(size(A));
B(:,:,1) = A(:,:,1);
%obtaining the blue colored objects
C = zeros(size(A));
C(:,:,3) = (255/max(max(A(:,:,3))))*A(:,:,3);
%separating the object from background
[kk,kk1] = size(C(:,:,3));
D = C;
D1 = im2bw(C,0.9);
D = 255*D1;
%combining the objects
D= C+B;
%finding the maximum location of orange object
for i = 10:kk-10
for j = 10:kk1-10
if B(i,j,1) >= max(max(B(:,:,1)))
B_m = i;
B_n = j;
break;
end
end
end
%estimating the surrounding objects and assigning required value %to E variable
E = A;
for i = 6:kk-6
for j = 6:kk1-6
if C(i,j,3)==max(max(C(:,:,3)))
if sum(sum(D(i-5:i+5,j-5:j+5,1)))>=100
E(i,j,1)=A(B_m,B_n,1);
E(i,j,2)=A(B_m,B_n,2);
E(i,j,3)=A(B_m,B_n,3);
end
end
end
end
figure,imshow(E,[]);
%you can use imwrite function to save the image in folder
%imwrite(E,’output.jpg’);
Refer to Imread, imwrite and Imshow function of Matlab
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Semantic Segmentation in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by