What to do in matlab when working with images

3 views (last 30 days)
So guys, i am working on images 3D rekonstruction with photometric stereo methode, which involve takin certain 2D images and process into 3D image. So my question is, after u take 6 pictures of surface that have 3840 x 2160 , what process should i do to make it smaller?. When i see photometric stereo example their dataset only have 512 x 34, how to achive this? what kind of process should i do? Pls guide me

Accepted Answer

Mathieu NOE
Mathieu NOE on 14 Jun 2023
hello
first code example :
%% Initalize the data
dataDir= fullfile(pwd); % select appropriate directory
exts = {'.jpg','.png','.tif'}; % choose valid file extensions like {'.jpg', '.png'}
resize_size = 100; % pixels size for output img
imds = imageDatastore(fullfile(dataDir),...
'IncludeSubfolders',true,'FileExtensions',exts,'LabelSource','foldernames');
countEachLabel(imds);
numImages = numel(imds.Files);
for i = 1:numImages
img = readimage(imds, i);
[m,n,p] = size(img);
% compute scale factor (same on both dimensions)
scale_factor = min(resize_size/m,resize_size/n);
img3= imresize(img, scale_factor);
figure(i),
img4= imshow(img3, 'InitialMagnification', 800);
drawnow;
Train{i} = (img3); %output image stored in cell
end
second example
% select appropriate options below and adapt code to your specific needs ...
% files = dir('*.tif'); % select all tiff files in current directory
files = dir('handheld*.tif'); % select only tiff files with "handheld" in the filename
% resize options (sacle factor or pixels)
scale_factor = 0.5;
% select portion of the image
% 451*279*3. I will like to extract a portion with dimensions of 120*80*3
x_dim = 120;
y_dim = 80;
x_offset = 100; % please make sure the "corner" of the cropped image is correct
y_offset = 50;
% output directory
out_dir = fullfile(pwd,'\out'); % from current directory to sub directory \out
% main loop
for ck = 1:length(files)
Filename = files(ck).name;
img = imread(Filename);
% resize
H{ck}= imresize(img, scale_factor);
% select (crop)
H{ck}= img(x_offset+(1:x_dim),y_offset+(1:y_dim),: );
% plot (just to check)
figure(ck), imagesc(H{ck});
% insert your own code here (save for example)
filename = ['out' num2str(ck) '.tiff'];
imwrite(H{ck},fullfile(out_dir,filename));
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!