How the number of times n of the patchwork increase?

조회 수: 3 (최근 30일)
John schwan
John schwan 2021년 8월 29일
댓글: John schwan 2021년 9월 4일
clc;
A=imread('C:\Users\hp\Desktop\matlab\pictures\lenna.png');%sample image
rnd_x = randperm(size(A,1)-128,7);%choose 7 random unique points on x-axis
rnd_y = randperm(size(A,2)-128,7);%choose 7 random unique points on y-axis
image(A)
for ii = 1:4
for jj = 5:7
piece{jj} = A((rnd_x(jj):(rnd_x(jj)+127)),(rnd_y(jj):(rnd_y(jj)+127)),1:3)+1;
A((rnd_x(jj):(rnd_x(jj)+127)),(rnd_y(jj):(rnd_y(jj)+127)),1:3)= piece{jj}; % add the changed pixel values to the original image A
a=imadjust(jj);
end
piece{ii} = A((rnd_x(ii):(rnd_x(ii)+127)),(rnd_y(ii):(rnd_y(ii)+127)),1:3)-1;%Convert chosen numbers to image pieces
A((rnd_x(ii):(rnd_x(ii)+127)),(rnd_y(ii):(rnd_y(ii)+127)),1:3)= piece{ii}; % add the changed pixel values to the original image A
b=imadjust(ii);
end
imshow(A)
The above is my coding running good but it give me the following error."Error using randperm K must be less than or equal to N.
Error in file (line 3)
rnd_x = randperm(size(A,1)-128,6000);%choose 7 random unique points on x-axis"
when I want to choose 6000 or 4000 random unique points on x-axis or y-axis in the place of 7 like the following code:
clc;
A=imread('C:\Users\hp\Desktop\matlab\pictures\lenna.png');%sample image
rnd_x = randperm(size(A,1)-128,6000);%choose 7 random unique points on x-axis
rnd_y = randperm(size(A,2)-128,6000);%choose 7 random unique points on y-axis
image(A)
for ii = 1:3000
for jj = 3001:6000
piece{jj} = A((rnd_x(jj):(rnd_x(jj)+127)),(rnd_y(jj):(rnd_y(jj)+127)),1:3000)+1;
A((rnd_x(jj):(rnd_x(jj)+127)),(rnd_y(jj):(rnd_y(jj)+127)),1:3000)= piece{jj}; % add the changed pixel values to the original image A
a=imadjust(jj);
end
piece{ii} = A((rnd_x(ii):(rnd_x(ii)+127)),(rnd_y(ii):(rnd_y(ii)+127)),1:3000)-1;%Convert chosen numbers to image pieces
A((rnd_x(ii):(rnd_x(ii)+127)),(rnd_y(ii):(rnd_y(ii)+127)),1:3000)= piece{ii}; % add the changed pixel values to the original image A
b=imadjust(ii);
end
imshow(A)
I actually need help in the number of times n of the patchwork increase from 7 up to 6000.

채택된 답변

Rik
Rik 2021년 8월 29일
You don't check if your image is actually large enough to allow 6000 unique indices. You should either reduce the number of samples in such a case, or increase the resolution of your image.
  댓글 수: 7
Rik
Rik 2021년 9월 2일
You're doing several indexing operations there. Have you checked the array sizes at that point?
piece{jj} = A( ...
(rnd_x(jj):(rnd_x(jj)+1)),...
(rnd_y(jj):(rnd_y(jj)+1)),...
1:3000) ...
+1;
  • Is rnd_x guaranteed to have at least jj elements?
  • Is the first dimension of A large enough to have at least rnd_x(jj)+1 elements?
  • Does the second dimension of A have rnd_y(jj)+1 elements?
  • Does the third dimension of A have 3000 elements?
John schwan
John schwan 2021년 9월 4일
Thank you very much. I will search them all. I hope to find a solution.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by