1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| % Petite image
small=rand(382,511);
% Grosse image
big=[zeros(100,550)
[small zeros(382,39)]
zeros(120,550)];
figure
subplot(2,2,1)
imagesc(small)
axis image
title('small')
subplot(2,2,2)
imagesc(big)
axis image
title('big')
% Recherche des indices des lignes contenant au moins un pixel non noir
idx_r=find(any(big,2));
% Recherche des indices des colonnes contenant au moins un pixel non noir
idx_c=find(any(big));
% Création de la table des pixels correspondant
[r,c]=meshgrid(idx_r,idx_c);
% Passage en indexage linéaire
idx=sub2ind(size(big),r(:),c(:));
% Création de la nouvelle image
new_small=zeros(size(big));
% Ajout de la petite image dans la nouvelle
new_small(idx)=small';
subplot(2,2,3)
imagesc(new_small)
axis image
title('new small')
% Vérification: si OK tout les pixels sont à 0
subplot(2,2,4)
imagesc(new_small-big)
axis image
title('new small-big') |
Partager