Create an empty array of size (MxN) for xlswrite.

7 visualizaciones (últimos 30 días)
Abhilash Sukumari
Abhilash Sukumari el 22 de Jun. de 2015
Respondida: Image Analyst el 22 de Jun. de 2015
I have an Image which is 1944® x 2592 (C). I would like to take one column at a time; treating each column as an Image and calculate how many pixels among each row of that column contains value > half(max) value of that column. Those number of pixels are to be written to the excel sheet corresponding to it's respective column.
Image: Image
Here is what I have tried so far, I am not able to write it successfully.
clc;
sig = rgb2gray(imread('1.bmp')); % read in the image.
% imshow(sig);
ArraySize = size(sig); %1944(R) x 2592 (C)
[maxval, maxloc] = max(sig(:)); % Gives the max and the location
maxval; % max value
[maxloc_row, maxloc_col] = ind2sub(size(sig), maxloc); % convert logical
%-------------------------------------------------------------------%
% Count pixels through each column > half(max) value of that column
%-------------------------------------------------------------------%
newfilename = 'Results.csv'; % write new values to .csv files
Array = zeros(2592,2592);
% % R = Array(:,1);
% y = Array(:,2);
for a = 1: 2592% maxloc_row = 635 maxloc_col = 1094
[a_maxval, a_maxloc] = max(sig(:,a)); % search max among every column.
% maxloc is the row at which maxval is.
newval = a_maxval/2; % averaged max value
% New structure for find width
x = 0;
x = Array(:, 1);
for b = 1: 1944 % maxloc_row = 635 maxloc_col = 1094
% R = b;
if sig(b,a) > newval
x=x+1;
end
end % End row search
x;
% y = x*(2.2); % pixels into microns
output = [num2cell(x)];
xlswrite(newfilename, output);
end % End column search

Respuestas (4)

James Tursa
James Tursa el 22 de Jun. de 2015
Editada: James Tursa el 22 de Jun. de 2015
If an array has size 2592 x 2, then it is not empty. An empty array has at least one dimension that has size 0. If you mean create an array with zeros, then
Array = zeros(2592,2);
  1 comentario
Abhilash Sukumari
Abhilash Sukumari el 22 de Jun. de 2015
No, I just want to initialize an array with dimensions: 2592 x 2

Iniciar sesión para comentar.


Chad Greene
Chad Greene el 22 de Jun. de 2015
Try
Array = NaN(2592,2) ;
  1 comentario
Abhilash Sukumari
Abhilash Sukumari el 22 de Jun. de 2015
I am later using xls write to write values into the array created by NaN, it would only write NaN. That is my problem. Let me edit the question to what I am trying to do.

Iniciar sesión para comentar.


Jeremy
Jeremy el 22 de Jun. de 2015
If you are writing to excel then you probably want to use a cell array,
Array = cell(2592,2);
  1 comentario
Abhilash Sukumari
Abhilash Sukumari el 22 de Jun. de 2015
Please have a look at the script. I am trying to write the x values to the excel. However, the final out in excel seems to show wrong with only one constant value in all 2592 rows.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 22 de Jun. de 2015
I'm surprised this even finished! You definitely don't want to call xlswrite 2592 times or it will take hours. Perhaps you opened up Excel to look at it after only a few of the calls to xlswrite had been executed.
You should create a 2D matrix for output and then put a single call to xlswrite after both "a" and "b" loops have finished.
Other problems: your (badly-named) x is just column 1 of Array every time. And you don't even need the loop over b because you can use the sum function: sum(x>newval) to count the number of pixels more than the half max value (which you chose the poor, non-descriptive name of newval for).

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by