Array Indexing Question MATLAB
Mostra commenti meno recenti
Hi I need help with a problem I am to take a 600x800x3 image and assign rid positions so that the first 100x100x3 is one square in position (1,1) and there will be 48 such squares. I am to make the specific square inputed into the function eg (1,1) would be the top left square of the image and set the entire square to black then call this function on a script file with nested loops to repeat this for the other 48 squares
Risposte (1)
Rik
il 28 Gen 2019
It is not the most beautiful code, but it works:
clc
figure(1),clf(1)
%get the default image
image;ax=get(gcf,'Children');
IM=get(ax,'Children');IM=get(IM,'CData');
c_ax=[0 128];IM=(IM-c_ax(1))/diff(c_ax);IM=uint8(255*IM);
IM=ind2rgb(IM,colormap('winter'));
%resize it to fit actual input
IM=imresize(IM,[600,800]);
imshow(IM)
IM_blocks=mat2cell(IM,...
100*ones(size(IM,1)/100,1),...
100*ones(size(IM,2)/100,1),...
3);
inds=reshape(1:numel(IM_blocks),size(IM_blocks'))';
for n=1:numel(IM_blocks)
%k=n;%for col-by-col
k=find(inds==n);
IM_blocks{k}(:)=0;
imshow(cell2mat(IM_blocks))
pause(0.05)
end
1 Commento
Rik
il 30 Gen 2019
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!