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

댓글 수: 2

Addy
Addy 2019년 1월 28일
편집: Addy 2019년 1월 28일
Kind of hard to follow. Could you post the sample data? and the code you tried?
asdf asdf
asdf asdf 2019년 1월 28일
So pretty much theres an image 600x800x3 and imagine it being split into 48 squares of size 100x100x3 each and these squares should have grid positions eg the top left square is (1,1) and the bottom right will be (6,8) the output of this function should be the image but now with a square (100x100x3) set to black so now the top left of the image is black. This function should called in a script file using nested loops with a 0.1 s pause showing the change. So pretty much the original image will start getting chopped off row by row going to black

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2019년 1월 28일

0 개 추천

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
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에 대해 자세히 알아보기

제품

질문:

2019년 1월 28일

댓글:

Rik
2019년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by