MATLAB: Creating a 2D circle with fixed hue, saturation and luminance and applying a gaussian filter

cielabcirclecolor spacegaussian filterImage Processing Toolbox

Hi,
I'm quite new to Matlab, so that's probably a dumb question. Anyway.. I'd appreciate any help.
I basically need to understand how:
1) to create a filled circle image (without background) in cielab space. The circle should have a r=125 pixels and fixed saturation (38) and luminance (85) values. the hue should be of 0 in cielab space
2) to apply a Gaussian low-pass filter of size 100 x 100 with a standard deviation of 10 only to the circle
3) to create a loop to replicate this operation, in order to save different circle images with same luminance and saturation, and different hue degrees in steps of 5 degrees each. in particular I would need the first circle to be 0 hue degrees, the second to be 5, the third to be 10 and so on – until they reach 250 degrees. so at the end I should have 51 circles with slightly different colours.
I had a look online and I understood – correct me if I'm wrong – that Matlab isn't able to manage image transparency. what would you suggest? After having those images, I would basically need to superimpose them on a black screen, so it would probably be a solution to save the final filtered image with a black background – but I have to be sure they will be reliable because they will be part of a behavioural visual experiment, and there is no room for errors.
below some code I used to create the filtered circle, but I'm not able to export it in cielab space and with no (or black) background. Also, I don't know how to create a loop!
% create a red circle.
set(gca,'Color','black')
cerchio_fig = rectangle('Position',[1,1,5,5],...
'Curvature',[1,1], 'FaceColor','r')
axis equal off;
saveas (cerchio_fig,'cerchio.png')
%%create a gaussian filter and save as a tiff
cerchio = imread('cerchio.png')
set(gcf,'Color','black')
cerchioblur = imgaussfilt(cerchio,10)
imwrite (cerchioblur,'cerchioblur.tiff')
%%imwrite (cerchioblur,'cerchioblur.tiff','Colorspace','cielab') %%when I
%%do that, my circle will be saved with completely different colours and
%%when opened back in matlab it will be converted to a different colour
%%space
imshow (cerchioblur)
Any suggestion?
Thanks in advance

Best Answer

By the way, here how I solved this (with Image Analyst help and patience):
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
% Create a logical image of a circle
rows = 280;
columns = 280;
[columnsInImage, rowsInImage] = meshgrid(1:columns, 1:rows);
centerX = 140;
centerY = 140;
radius = 125;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
image(circlePixels) ;
axis('off', 'image');
colormap([0 0 0; 1 1 1]);
% loop to create 51 circles 5 degrees step, L 85 S 38
for hueAngle = 0 : 5 : 250
tic;
hueChannel = zeros(rows, columns);
hueChannel(circlePixels) = hueAngle / 360; % Normally goes from 0-1 which is 0-360 degrees.
saturationChannel = zeros(rows, columns);
saturationChannel(circlePixels) = 38/100;
valueChannel = zeros(rows, columns);
valueChannel(circlePixels) = 85/100;
hsvImage = cat(3, hueChannel, saturationChannel, valueChannel);
rgbImage = hsv2rgb(hsvImage);
imwrite(rgbImage,sprintf('circle_%d.png', hueAngle))
if hueAngle == 0
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
end
end
% apply low pass gaussian filter, 10 SD
files = dir('C:\Users\andre\OneDrive\Desktop\prove_matlab\stimuli\*.png');
for k = 1 : length(files)
thisName = files(k).name
fullFileName = fullfile('C:\Users\andre\OneDrive\Desktop\prove_matlab\stimuli\', files(k).name)
theImage = imread(fullFileName);
subplot(1, 2, 1);
imshow(theImage);
drawnow;
blurredImage = imgaussfilt(theImage, 10);
subplot(1, 2, 2);
imshow(blurredImage);
drawnow;
outputBaseFileName = sprintf('blur_%s', thisName);
outputFullFileName = fullfile('C:\Users\andre\OneDrive\Desktop\prove_matlab\stimuli\', outputBaseFileName)
imwrite(blurredImage, outputFullFileName);
end