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

110 views (last 30 days)
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

Answers (2)

Akira Agata
Akira Agata on 26 Mar 2020
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 on 18 Sep 2022
% 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)

Community Treasure Hunt

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

Start Hunting!