Problem using RESHAPE function

There is a attach file of this project and screenshot of the problem. It is better to run the project and test yourself.

function btnRastr_Callback(hObject, eventdata, handles)
global PathName;
global FileName;
if FileName ~= 0
    FullN = [PathName FileName];
    try
        k = imread(FullN);
        gor = size(k,2);
        vert = size(k,1);
        r = k(:,:,1);
        g = k(:,:,2);
        b = k(:,:,3);
        dr = double(r);
        dg = double(g);
        db = double(b);
        dc = 1-dr/255;
        dm = 1-dg/255;
        dy = 1-db/255;
        var_k = ones(vert,gor);
          for i = 1:vert;
              for j = 1:gor;
                  if (dc(i,j) < var_k(i,j));
                      var_k(i,j) = dc(i,j);
                  end
                  if(dm(i,j) < var_k(i,j));
                      var_k(i,j) = dm(i,j);
                  end
                  if(dy(i,j) < var_k(i,j));
                      var_k(i,j) = dy(i,j);
                  end
                  if(var_k(i,j) == 1);
                      dc(i,j) = 0;
                      dm(i,j) = 0;
                      dy(i,j) = 0;
                  else
                      dc(i,j) = (dc(i,j)-var_k(i,j))/(1-var_k(i,j));
                      dm(i,j) = (dm(i,j)-var_k(i,j))/(1-var_k(i,j));
                      dy(i,j) = (dy(i,j)-var_k(i,j))/(1-var_k(i,j));
                  end
                  j = j+1;
              end
              i = i+1;
          end
          k = var_k;
          img = reshape(k,160000,[]);
          load network_one.mat
          a = network1(img);
          if a == 0
              set(handles.text1,'String','Портрет');
              rastr_fase(PathName, FileName);
          elseif a == 1
              load network_two.mat;
              b = network2(img);
              if b == 0
                  set(handles.text1,'String','Чертеж');
                  rastr_draw(PathName, FileName);
              elseif b == 1;
                  set(handles.text1,'String','Природа');
                  rastr_natur(PathName, FileName);
              end
          end
      catch exception
          errordlg('Ошибка чтения файлов!','Ошибка');
          rethrow(exception);
      end
  else errordlg('Не выбран файл!','Ошибка');
  end

回答(1 个)

Guillaume
Guillaume 2018-4-19
编辑:Guillaume 2018-4-19

0 个投票

Your image has 93274 pixels, it's probably a rectangle of 298x313 pixels. You're trying to reshape it into something that has 160000 rows. You don't even have enough pixels to fill one column of that something.

Your code is simply not design to work with images that size. You need to either use images that match the size your code expects (the number of pixels must be a multiple of 160000) or change your code so it works with images of any size.

2 个评论

I want to change my code so it works with images of any size, but I don't know how(
Well, what is the purpose of that reshape? Why does the image has to be reshaped in 160000 rows exactly at the moment?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by