
dividing each block of each imge into sub_blocks
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
hello,i want to dividing set of images into blocks and then divide each block into 9 sub_blocks,also i want to save each blocks for each image in sparate array,how can work this please???
i have this code for dividing into blocks
a=157;
b=300;
scr=dir('C:\users\hp\Desktop\dataset\*.jpg');
for i=1:length(scr)
f=strcat('C:\users\hp\Desktop\dataset\',scr(i).name);
j=imread(f);
jj=imresize(j,[628,1200]);
figure,imshow(a);
path=strcat('C:\users\hp\Desktop\dataset\',scr(i).name);
g=mat2cell(jj,[a a a a],[b b b b],3);
for i=1:16
   subplot(4,4,i),imshow(g{i});
end
0 个评论
回答(1 个)
  Image Analyst
      
      
 2022-8-23
        Too many problems to explain them all (like showing "a", using path as a new variable, not checking for gray scale images, not looping over all rows and columns of "g", etc.).  Just try this instead:
% Demo by Image Analyst
% Initialization Steps.
clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.
workspace;  % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
a=157;
b=300;
fileList = dir('*.jpg');
for k = 1 : length(fileList)
    thisFileName = fullfile(fileList(k).folder,fileList(k).name);
    thisImageOriginal = imread(thisFileName);
    [rows, columns, numberOfColorChannels] = size(thisImageOriginal);
    if numberOfColorChannels < 3
        % Skip gray scale images or you'll get an error.
        continue;
    end
    resizedImage = imresize(thisImageOriginal, [628,1200]);
    g = mat2cell(resizedImage, [a a a a], [b b b b], 3);
    [rowsg, colsg] = size(g);
    counter = 1;
    for row = 1 : rowsg
        for col = 1 : colsg
            subplot(rowsg, colsg, counter);
            imshow(g{row, col});
            counter = counter + 1;
        end
    end
    sgtitle(fileList(k).name, 'FontSize', 16, 'Interpreter', 'none'); % Only in R2018b or later.
    promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
    titleBarCaption = 'Continue?';
    buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
    if contains(buttonText, 'Quit', 'IgnoreCase', true)
        return; % or break or continue.
    end
end

3 个评论
  Image Analyst
      
      
 2022-8-24
				
      编辑:Image Analyst
      
      
 2022-8-24
  
			Looks like no more answers are going to come in.  What exactly about my answer is unacceptable?  I'm not sure what you mean when you say 9 blocks since your attempt at code seemed to try to create 16 blocks.  Maybe you could give a screenshot of what you'd prefer instead of this.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

