Array Indexing Question MATLAB
이전 댓글 표시
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
답변 (1개)
Rik
2019년 1월 28일
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
Rik
2019년 1월 30일
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.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!