(Important )How to generate numbers in matlab? Need help.

Hi everyone. I have a question. I want to make an automatic image rescaling using a random number as follow. How can i make it so that xb variable will be bigger than xa variable as the function randscale stated than xb cannot be same and bigger than xa? I think using linspace also gives me error. Thanks for helping.
clear;
clc;
img1 = imread('peppers.png');
data=100;
for i=1:data
xmin=0.001;
xmax=1;
n=data;
xa=fliplr(round(xmin+linspace(1,n)*(xmin+xmax)));
xb=round(xmin+linspace(1,n)*(xmax-xmin));
augmenter = imageDataAugmenter('RandScale',[xa xb]);
S=augment(augmenter,img1);
imwrite(S, [pathname '\' fol '_imagescaling' num2str(i) '.png']);
end

 Réponse acceptée

You can generate 2 random numbers in the given range and sort these 2 numbers out.
img1 = imread('peppers.png');
data=5; %100;
for i=1:data
xmin=0.001;
xmax=1;
% n=data;
% xa=fliplr(round(xmin+linspace(1,n)*(xmin+xmax)));
% xb=round(xmin+linspace(1,n)*(xmax-xmin));
xab = rand(1, 2)*(xmax-xmin) + xmin;
xab = sort(xab);
%augmenter = imageDataAugmenter('RandScale',[xa xb]);
augmenter = imageDataAugmenter('RandScale', xab);
S=augment(augmenter,img1);
%imwrite(S, [pathname '\' fol '_imagescaling' num2str(i) '.png']);
end

Plus de réponses (1)

clc; clear all; close all;
img1 = imread('peppers.png');
data=100;
for i=1:data
xmin=0.001;
xmax=1;
% n=data;
% xa=fliplr(round(xmin+linspace(1,n)*(xmin+xmax)));
% xb=round(xmin+linspace(1,n)*(xmax-xmin));
rate = sort(abs(randn(1, 2)));
augmenter = imageDataAugmenter('RandScale',rate);
S=augment(augmenter,img1);
imwrite(S, [pathname '\' fol '_imagescaling' num2str(i) '.png']);
end

1 commentaire

Fitz Amin
Fitz Amin le 10 Nov 2021
Modifié(e) : Fitz Amin le 10 Nov 2021
Thank you sir for the knowledge. It also worked.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by