Create an empty array of size (MxN) for xlswrite.
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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.
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
0 comentarios
Respuestas (4)
  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);
  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);
  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).
0 comentarios
Ver también
Categorías
				Más información sobre Multidimensional Arrays en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




