Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

I need you help to convert this equation to matlab code

1 Ansicht (letzte 30 Tage)
elor hdd
elor hdd am 17 Sep. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
clear all;
close all;
clc;
tic
%-----------------read image
o=imread('4.2.07.tiff');
[m,n]=size(o);
%----------------random pixel insertion ------
for i=1:m
for j=1:n
if j==1
I(i,j)=randi(i)
else
I(i,j)=o(i,j-1)
end
end
end
this code does'nt work

Antworten (2)

drummer
drummer am 23 Okt. 2020
Bearbeitet: drummer am 23 Okt. 2020
Looks funny this exercise.
By assigning i to the rand function, it is creating matrices as i increases. So rand(2) creates a 2 x 2 matrix of random values , rand(3) creates a matrix of 3 x 3 and so on...
So rand(i) would be growing in dimension sizes, as i iterates. And not assigning a single random value to the ith element.
@Samiu is correct, I think, regarding the limits of j.
Well, after all, this exercise should give an image with random values only in the first column, and return the original image otherwise?
Check if it is what you're looking for.
- The attached file shows the original in the left, and a zoom in the right to show the random values assigned to the 1st column.
Cheers
clear all;
close all;
clc;
% tic
%-----------------read image
o = imread('pout.tif');
figure
imshow(o);
title('original image');
%%
[m, n] = size(o);
I = zeros(m, n);
%----------------random pixel insertion ------
for i = 1 : m
for j = 1 : n + 1
if j == 1
I(i,j) = rand;
else
I(i,j) = o(i,j-1);
end
end
end
figure
imshow(I, 'DisplayRange', []);
title('Image I')

Samiu Haque
Samiu Haque am 17 Sep. 2020
I think the second for loop is supposed to iterate 'n+1' times and not 'n' times. As I(i,j) has the dimension of m*(n+1)

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by