Array Indexing Question MATLAB
Mostrar comentarios más antiguos
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
Respuestas (1)
Rik
el 28 de En. de 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 comentario
Rik
el 30 de En. de 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.
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!