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 comentarios

Addy
Addy el 28 de En. de 2019
Editada: Addy el 28 de En. de 2019
Kind of hard to follow. Could you post the sample data? and the code you tried?
asdf asdf
asdf asdf el 28 de En. de 2019
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

Iniciar sesión para comentar.

Respuestas (1)

Rik
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
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.

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Preguntada:

el 28 de En. de 2019

Comentada:

Rik
el 30 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by