Looking for imaging processing expert to assembly back cropped images
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi
I am looking for how to assebmly back cropped images
I trained the neural network and used training images and test images with cropped ones
I need in (Reconstructed images from test images) to have assembel back the cropped images as one image for each
Herein the code
close all;
clc;
%% Initalize the data
dataDir= fullfile('Data/');
exts = {'.jpg','.png','.tif','BMP'};
imds = imageDatastore(fullfile(dataDir),...
'IncludeSubfolders',true,'FileExtensions','.jpg','LabelSource','foldernames');
countEachLabel(imds);
[TrainData, TestData] = splitEachLabel(imds, 0.5);
size(TrainData);
countEachLabel(TrainData);
numImages = numel(TrainData.Files);
dx = 25;
dy = 25;
w = dx - 1;
h = dy - 1;
for i = 1:numImages
img = readimage(TrainData, i);
img=rgb2gray(img);
img3= im2double(img);
scale = 0.5;
img8 = imresize(img3,scale);
for x = 0:3
for y = 0:3
ofs_x = 1 + x * dx;
ofs_y = 1 + y * dy;
img_crop = imcrop(img8,[ofs_x ofs_y w h]);
%img4 = imshow(img_crop, 'InitialMagnification',800);
%drawnow;
idx = (i-1)*16 + y*4 + x + 1;
% 1 2 4 5
% 6 7 8 9
% 10 11 12 13
% 14 15 16 17
Train{idx} = (img_crop); %#ok<SAGROW>
end
end
end
hiddenSize = 50;
autoenc = trainAutoencoder(Train,hiddenSize,'MaxEpochs',2000,...
'DecoderTransferFunction','purelin','EncoderTransferFunction','satlin','L2WeightRegularization',0.004,'SparsityRegularization',4,'SparsityProportion',0.15);
numImages = numel(TestData.Files);
for i = 1:numImages
img = readimage(TestData, i);
img=rgb2gray(img);
img3= im2double(img);
scale = 0.5;
img8 = imresize(img3,scale);
for x = 0:3
for y = 0:3
ofs_x = 1 + x * dx;
ofs_y = 1 + y * dy;
img_crop = imcrop(img8,[ofs_x ofs_y w h]);
%img4 = imshow(img_crop, 'InitialMagnification',800);
%drawnow;
idx = (i-1)*16 + y*4 + x + 1;
% 1 2 4 5
% 6 7 8 9
% 10 11 12 13
% 14 15 16 17
Test{idx} = (img_crop); %#ok<SAGROW>
end
end
end
xReconstructed = predict(autoenc,Test);
%% Test Images
figure();
for i = 1:20
subplot(4,5,i);
imshow(TestData.Files{i});
end
%% Reconstructed images from TestData
figure();
for i = 1:20
subplot(4,5,i);
reconstructed = xReconstructed{i};
reconstructed(imbinarize(reconstructed)) = 1;
imshow(reconstructed)
end
I would like to assemble back the cropped images as one image for each in this part from the code above
%% Reconstructed images from TestData
figure();
for i = 1:20
subplot(4,5,i);
reconstructed = xReconstructed{i};
reconstructed(imbinarize(reconstructed)) = 1;
imshow(reconstructed)
end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!