I have to resize my image to a fix size of 256*256 and then I have to divide the image into two 2*2 non overlapping blocks? i have made this code but its not working on my image
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
img=imread('cameraman.tif');
[m n]=size(img);
block=4;
%slide_len=1;
for ix=0:block:m-block
for jy=0:block:n-block
current_block=img((ix+1):(ix+block),(jy+1):(jy+block));
dct_coeff((ix+1):(ix+block),(jy+1):(jy+block))=current_block;
end
end
subplot(2,1,1)
imshow(dct_coeff);
fun=@dct2;
c=blkproc(img,[4 4],fun);
subplot(2,1,2)
imshow(c);
0 comentarios
Respuestas (2)
Image Analyst
el 7 de Oct. de 2013
image256x256 = imresize(img, [256, 256]);
See if the FAQ helps you with blockproc(): http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F
0 comentarios
Ranu Bhardwaj
el 28 de Dic. de 2017
img_Folder = fullfile(matlabroot, '\toolbox\images\imdemos');
F1 = 'cameraman.tif';
F1_name = fullfile(img_Folder, F1); %#ok<NASGU>
if ~exist(F1_name, 'file')
F1_name = F1; % No path this time.
if ~exist(F1_name, 'file')
errormsg = sprintf('Error: %s does not exist.', F1_name);
uiwait(warndlg(errormsg));
return;
end
end
grayimg = imread(F1_name);
[rows columns numberOfColorBands] = size(grayimg); %#ok<NCOMMA>
figure;
subplot(2, 2, 1);
imshow(grayimg, []);fontSize=10;
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
blockSizeR = 128; % Rows in block.
blockSizeC = 128; % Columns in block.
wholeBlockRows = floor(rows / blockSizeR);
wholeBlockCols = floor(columns / blockSizeC);
image3d = zeros(wholeBlockRows, wholeBlockCols, 3);
img = 1;
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2); % Don't let it go outside the image.
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2); % Don't let it go outside the image.
First_img = grayimg(row1:row2, col1:col2);
subplot(2, 2, img);
imshow(First_img);
drawnow;
if (row2-row1+1) == blockSizeR && (col2-col1+1) == blockSizeC
image3D(:, :, img) = First_img; %#ok<SAGROW>
else
Blocl = [(row2-row1+1), (col2-col1+1)];
warningMessage = sprintf('Warning: this block size of %d rows and %d columns\ndoes not match the preset block size of %d rows and %d columns.\nIt will not be added to the 3D image stack.',...
Blocl(1), Blocl(2), blockSizeR, blockSizeC);
uiwait(warndlg(warningMessage));
end
img = img + 1;
end
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!