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

23 次查看(过去 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