how can i change this error

I am expecting a function.
I want to divide an image in grids. In this way the image is divided in 5x6.
cuadrícula means grid (in spanish).
imshow('asteroideHito2.jpg'); %This is the image to divide in 200x200 sections.And its original size is 1200x1000.
title('Imagen de búsqueda');
for i=1:6
for j=1:5
Cuadricula (i*j);
end
end

5 Comments

Stephen23
Stephen23 on 3 Jan 2022
Edited: Stephen23 on 3 Jan 2022
"May someone give me a solution?"
Solution: define Cuadricula.
Do you expect Cuadricula to be a function or an array? If either of these, where is it defined?
I am expecting a function.
I want to divide an image in grids. In this way the image is divided in 5x6.
cuadrícula means grid (in spanish).
imshow('asteroideHito2.jpg'); %This is the image to divide in 200x200 sections.And its original size is 1200x1000.
title('Imagen de búsqueda');
for i=1:6
for j=1:5
Cuadricula (i*j);
end
end
"I am expecting a function."
Where did you get Cuadricula from? Did you write it yourself? Or did you it download it or get given it by friend/tutor ?
info: ImagenDeBusqueda is an image of 1200x1000.
I explain you, I want to divide the image in different grids. Then I want to assign each gread to a dimension of the image. e.g. Grid(1,1)= ImagenDeBusqueda(1:200,1:200). And I want to do it to loops because if I do it manually there will be so many operations.
For that, see my second answer below: Click here to scroll down and see it

Sign in to comment.

 Accepted Answer

To process the image as a sequence of tiles:
rgbImage = imread('peppers.png');
imshow(rgbImage); %This is the image to divide in 200x200 sections.And its original size is 1200x1000.
axis('on', 'image')
title('Imagen de búsqueda');
[rows, columns, numberOfColorChannels] = size(rgbImage)
numTiles = [6, 4]; % Number of tiles Vertical, horizontal.
% Get the rows where each of the tile starts.
rowStarts = round(linspace(1, rows+1, numTiles(1)+1));
rowEnds = rowStarts(2:end) - 1
rowStarts = rowStarts(1:end-1) % Ignore the last one.
% Get the columns where each of the 6 tile starts.
colStarts = round(linspace(1, columns+1, numTiles(2)+1));
colEnds = colStarts(2:end) - 1
colStarts = colStarts(1:end-1)
plotCount = 1;
for row = 1 : length(rowStarts)
for col = 1 : length(colStarts)
subImage = rgbImage(rowStarts(row) : rowEnds(row), colStarts(col) : colEnds(col), :);
subplot(numTiles(1), numTiles(2), plotCount);
plotCount = plotCount + 1;
imshow(subImage);
% Now process subImage somehow...
end
end
See the FAQ:

2 Comments

Ok, could you explain me the function of linspace and round?
Thanks a lot guy!
linspace() gives a specified number of values between a starting value and an ending value. Like if your image was 15 pixels wide and you wanted to divide that up into 3 tiles of 5 pixels each:
startingColumns = linspace(1, 15+1, 4)
startingColumns = 1×4
1 6 11 16
% Get rid of last one that is past the end of the image.
startingColumns = startingColumns(1:end-1)
startingColumns = 1×3
1 6 11
So we'd go from 1 to 5, 6 to 10, and 11 to 15.
round() takes the numbers, which may have fractional parts, and makes them integers. This is because when we're indexing to get the subimages you have to start and stop on integer rows and columns. You can't begin on line 12.345 and end on line 65.876. You'd have to start on line 12 and end on line 66.
If it does what you want, can you click "Accept this answer" or the Vote icon.

Sign in to comment.

More Answers (1)

There is no such function on your search path. Try using xline() and yline() to make a grid in the overlay.
rgbImage = imread('peppers.png');
imshow(rgbImage); %This is the image to divide in 200x200 sections.And its original size is 1200x1000.
axis('on', 'image')
title('Imagen de búsqueda');
[rows, columns, numberOfColorChannels] = size(rgbImage)
rows = 384
columns = 512
numberOfColorChannels = 3
for row = 1 : rows/6 : rows
fprintf('Putting line at row %d.\n', row);
yline(row, 'Color', 'y', 'LineWidth', 2);
end
Putting line at row 1. Putting line at row 65. Putting line at row 129. Putting line at row 193. Putting line at row 257. Putting line at row 321.
for col = 1 : columns/6 : columns
fprintf('Putting line at row %d.\n', col);
xline(col, 'Color', 'y', 'LineWidth', 2);
end
Putting line at row 1. Putting line at row 8.633333e+01. Putting line at row 1.716667e+02. Putting line at row 257. Putting line at row 3.423333e+02. Putting line at row 4.276667e+02.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!