Adjusting the size of images
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
My function needs to adjust images that are either larger or smaller than 255 x 255 to be 255 x 255. Here is the code I have so far but it doesn't.
function [outImage] = adjust_img(img)
%cast to double
img = double(img);
%make variables row and col the size of the img
[row,col,n] = size(img);
outImage = img;
%for loops to loop through each row, column, and layer
for i = 1:row
for j = 1:col
%if img is greater than 255 to equal 255
if img(i,j,:) > 255
img(i,:) = 255;
end
%if img is less than 0 to equal 0
if img(i,j,:) < 0
img(i,j,:) = 0;
end
end
end
outImage = img(i,j,k);
end
0 Kommentare
Antworten (1)
Star Strider
am 6 Mär. 2016
I’m having problems following your code, since I can’t tell if you want each pixel to be limited to (0,255) or if you want the image size itself to be a matrix of (255x255).
If you want the range of values limited, this works:
ImD = 100 + 100*randn(10); % Create Matrix
ImL = (ImD < 0)*0; % Set Elements < 0 = 0
ImH = (ImD > 255)*255; % Set Elements > 255 = 255
ImC = (ImD >=0 ) & (ImD <= 255); % All Other Elements
Im2 = ImL + ImH + ImC.*ImD; % Add Matrices To Create Result
If you want the matrix size limited to (255x255), use the imresize function.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Geometric Transformation and Image Registration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!