clc;
close all;
imtool close all;
clear;
workspace;
format longg;
format compact;
fontSize = 20;
rgbImage=imread('onion.png');
subplot(3,4, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
subplot(3,4, 2);
imshow(redChannel);
title('Red Image', 'FontSize', fontSize);
subplot(3,4, 3);
imshow(greenChannel);
title('Green Image', 'FontSize', fontSize);
subplot(3,4, 4);
imshow(blueChannel);
title('Blue Image', 'FontSize', fontSize);
sobelFilteredImageR = imgradient(redChannel);
sobelFilteredImageG = imgradient(greenChannel);
sobelFilteredImageB = imgradient(blueChannel);
colorSobel = cat(3, sobelFilteredImageR, sobelFilteredImageG, sobelFilteredImageB);
subplot(3,4, 6);
imshow(sobelFilteredImageR, []);
title('Red Sobel Image', 'FontSize', fontSize);
subplot(3,4, 7);
imshow(sobelFilteredImageG, []);
title('Green Sobel Image', 'FontSize', fontSize);
subplot(3,4, 8);
imshow(sobelFilteredImageB, []);
title('Blue Sobel Image', 'FontSize', fontSize);
weighting = 0.1;
outputImage = rgbImage + uint8(weighting * colorSobel);
subplot(3,4, 9);
imshow(outputImage);
caption = sprintf('Weighting of %.2f', weighting);
title(caption, 'FontSize', fontSize);
weighting = 0.4;
outputImage = rgbImage + uint8(weighting * colorSobel);
subplot(3,4, 10);
imshow(outputImage);
caption = sprintf('Weighting of %.2f', weighting);
title(caption, 'FontSize', fontSize);
weighting = 0.7;
outputImage = rgbImage + uint8(weighting * colorSobel);
subplot(3,4, 11);
imshow(outputImage);
caption = sprintf('Weighting of %.2f', weighting);
title(caption, 'FontSize', fontSize);
weighting = 1.0;
outputImage = rgbImage + uint8(weighting * colorSobel);
subplot(3,4, 12);
imshow(outputImage);
caption = sprintf('Weighting of %.2f', weighting);
title(caption, 'FontSize', fontSize);
Best Answer