Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

I have to create an array having grid points and its co-ordinates in it ?

1 Ansicht (letzte 30 Tage)
jetashri gandhi
jetashri gandhi am 11 Apr. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I have to create an array having three values (value,x-coordinate,y-coordinate) of the image named dMap. The following code I have been running but its not working.
Main file:
params.topRow=200;
params.topColum=330;
params.skipPoints = 5;
params.numberOfGrids = 10;
params.gridCollumns = 20;
params.gridRows = 20;
params.bottomColum=1;
dMap= imread('disp01.png');
[dMapRow, dMapColum]=size(dMap);
params.dMapColum=dMapColum;
params.dMapRow =dMapRow;
randomGrids=createRandomGrids(params,dMap);
Function File:
function [randomGrids]=createRandomGrids(params,dMap)
numberOfGrids = params.numberOfGrids;
gridCollumns = params.gridCollumns;
gridRows = params.gridRows;
topRow=params.topRow;
topColum=params.topColum;
bottomRow=params.bottomRow;
bottomColum=params.bottomColum;
dMapColum=params.dMapColum;
% heigth of a grid (region of interest)
gridHeight = abs(topRow - bottomRow);
% number of lines between the rows in the grid
rowsBlockGrid = round(gridHeight/gridRows)-1;
% By how much the width of the next row changes, relative to the previous row
stepInc=abs((topColum-bottomColum)/(bottomRow-topRow));
randomRowsNumbersAllGrids = cell(numberOfGrids,1);
randomRowsNumbersOneGrid = zeros(gridRows,1);
% Create an array of random numbers, used to select the rows in a grid
for ii = 1:numberOfGrids
for jj = 1:gridRows
randomRowsNumbersOneGrid(jj,1) = round(topRow + rowsBlockGrid*(jj-1) + rowsBlockGrid*rand);
end
randomRowsNumbersAllGrids{ii,1} = randomRowsNumbersOneGrid;
end
randomGrids = cell(numberOfGrids,1);
randomGrid = zeros(gridRows*gridCollumns,3);
% Create grids of points
for ff = 1:numberOfGrids
step=0;
%Go through all rows in a grid
for ii=1:gridRows
% current row in the region of interest (the size changes as ROI
% is a trapezium)
currentRow=round(topColum-stepInc*step):round(dMapColum-topColum+stepInc*step);
step=randomRowsNumbersAllGrids{ff,1}(ii,1)-topRow +1;
% index of the current row in an image
idx = randomRowsNumbersAllGrids{ff,1}(ii,1);
% Copy spaced points from the image into a grid
for currentCollumn=1:gridCollumns
[~,currentRowSize] = size(currentRow);
numberOfLinesBetweenGridRows = round(currentRowSize/gridCollumns);
index = ((ii-1)*gridCollumns+currentCollumn);
randomGrid(index,3) = currentRow(1,1)+round(numberOfLinesBetweenGridRows*currentCollumn);
randomGrid(index,2) = idx;
randomGrid(index,1)= dMap(idx,round(currentRow(1,1)+numberOfLinesBetweenGridRows*currentCollumn));
end
end
randomGrids{ff,1} = randomGrid;
end
end

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by