hwo can i do this image that shades from white at the image edges to black in the image centre

조회 수: 7 (최근 30일)
imageData=[]; % set up an empty array
imSize=100;
numRows=imSize;
numCols=imSize;
%populate using a nested loop
for row=[numRows:-1:1]
imageRow=[]; %empty vector for row
for col=[numCols:-1:1]
pixelVal=(col+row)/(imSize*2); % make a pixel val in 0..1
imageRow=[imageRow pixelVal]; %add value for pixel
end
imageData=[imageData; imageRow]; % add row of pixels
end
for row=[1:numRows]
imageRow=[]; %empty vector for row
for col=[numCols:-1:1]
pixelVal=(col+row)/(imSize*2); % make a pixel val in 0..1
imageRow=[imageRow pixelVal]; %add value for pixel
end
imageData=[imageData; imageRow]; % add row of pixels
end
for row=[numRows:-1:1]
imageRow=[]; %empty vector for row
for col=[1:numCols]
pixelVal=(col+row)/(imSize*2); % make a pixel val in 0..1
imageRow=[imageRow pixelVal]; %add value for pixel
end
imageData=[imageData; imageRow]; % add row of pixels
end
for row=[1:numRows]
imageRow=[]; %empty vector for row
for col=[1:numCols]
pixelVal=(col+row)/(imSize*2); % make a pixel val in 0..1
imageRow=[imageRow pixelVal ]; %add value for pixel
end
imageData=[imageData;imageRow]; % add row of pixels
end
% display as an image
imshow(imageData);
but i want this picture like

답변 (2개)

Akira Agata
Akira Agata 2020년 3월 26일
I believe you can do this more efficiently. The following is an example:
% Set image size
imSize = 100;
% Make a left-top part of the image
[xGrid,yGrid] = meshgrid(1:imSize,1:imSize);
xGrid = fliplr(xGrid);
yGrid = flipud(yGrid);
imageData = (xGrid+yGrid)/(imSize*2);
% Concatenate with rotating the left-top image
imageData = [...
imageData, rot90(imageData,-1);...
rot90(imageData), rot90(imageData,2)];
% Show the result
figure
imshow(imageData)

Sahil
Sahil 2022년 9월 18일
% Set image size imSize = 100;
% Make a left-top part of the image [xGrid,yGrid] = meshgrid(1:imSize,1:imSize); xGrid = fliplr(xGrid); yGrid = flipud(yGrid); imageData = (xGrid+yGrid)/(imSize*2);
% Concatenate with rotating the left-top image imageData = [... imageData, rot90(imageData,-1);... rot90(imageData), rot90(imageData,2)];
% Show the result figure imshow(imageData)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by