MATLAB: What is the result of combining equalized image with a sobel filter

feature analyisisimage processingMATLABsobel

Hi,
I was trying various things to make text stand out more in images. A hack which I came up with was by applying the sobel filter for vertical then horizontal to the rgb image then adding it an equalized version of the original image (code snippet below). However I couldn't segment or binarize the image, but it seems to make all text and well defined features darker almost as if it added some texture to the image. Please let me know if anyone knows what's going on here, im quite interested to find out whats happening.
IM=imread('image.jpg');
% Apply horizontal and vertical sobel filters:
h=fspecial('sobel');
filt=imfilter(IM,h);
filt=imfilter(filt,h');
% Equalize the image:
r=squeeze(IM(:,:,1));
g=squeeze(IM(:,:,2));
b=squeeze(IM(:,:,3));
rgb=r+g+b;
R=r./rgb;G=g./rgb;B=b./rgb;
EQ=cat(3,R,G,B);
% Resultant image seems to have amplified curves:
IMNEW= filt + EQ;

Best Answer

No, you're doing it all wrong. I started to try to fix your code, but it's better to just start from scratch and do it the right way from step 1. Here, try this way, using imgradient():
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.
format longg;
format compact;
fontSize = 20;
% Read in RGB image.
rgbImage=imread('onion.png');
% Display image.
subplot(3,4, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display images.

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);
% Apply Sobel filters:
sobelFilteredImageR = imgradient(redChannel);
sobelFilteredImageG = imgradient(greenChannel);
sobelFilteredImageB = imgradient(blueChannel);
% Combine them all so we can add to original
colorSobel = cat(3, sobelFilteredImageR, sobelFilteredImageG, sobelFilteredImageB);
% Display images.
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);
% Add together with three different weightings.
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);