Split and image 128x138 into 16 subimages of 32x32 and create a new one using those subimages randomly

4 vues (au cours des 30 derniers jours)
Take and CT image of 128x128 (previous resize) and split it into 16 subimages of 32x32, finally create a new "artificial CT" image using those subimages randomly. Captura shows CT and subimages from this CT, Captura2 shows a "artificial CT". I have this code for the first part:
% Read in image
grayImage = imread('pout.tif');
[rows, columns, numColorChannels] = size(grayImage)
imshow(grayImage);
axis on;
impixelinfo
numBandsVertically = 4;
numBandsHorizontally = 3;
topRows = round(linspace(1, rows+1, numBandsVertically + 1))
leftColumns = round(linspace(1, columns+1, numBandsHorizontally + 1))
% Extract into subimages and display on a new figure.
hFig2 = figure();
plotCounter = 1;
for row = 1 : length(topRows) - 1
row1 = topRows(row);
row2 = topRows(row + 1) - 1;
for col = 1 : length(leftColumns) - 1
col1 = leftColumns(col);
col2 = leftColumns(col + 1) - 1;
subplot(numBandsVertically, numBandsHorizontally, plotCounter);
subImage = grayImage(row1 : row2, col1 : col2, :);
imshow(subImage);
caption = sprintf('Rows %d-%d, Columns %d-%d', row1, row2, col1, col2);
title(caption);
drawnow;
plotCounter = plotCounter + 1;
end
end

Réponse acceptée

Matt J
Matt J le 4 Mai 2022
Modifié(e) : Matt J le 4 Mai 2022
Using mat2tiles (which you must download).
grayImage=imresize(imread('pout.tif'),[128,128]);
blocks = mat2tiles( grayImage, [32,32]);
blocks(:)=blocks(randperm(16));
imshow(cell2mat(blocks));

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by