I have images with no background (which i obtained via image masking) that I'm trying to upload on Matlab. However, Matlab keeps (automatically) adding a black background to my images. This poses a problem when I try to use histogram equalization, with the function histeq(), as the dark background seems to affect the process of color adjustment. Is there a way to use histogram equalization on the image itself without accounting for the background?
[img, ~, transp] = imread('https://upload.wikimedia.org/wikipedia/commons/a/ac/NewTux.png'); alphadata = im2double(transp); subplot(1,2,1) h = imshow(img); h.AlphaData = alphadata;
Alpha data is not necessarily just 0 (transparent) or maximum (completely opaque) so you need to decide whether for histogram equalization you want anything non-zero to be included, or anything non-maximum to be excluded.
mask = alphadata >= 0.5;
And now you can
masknd = repmat(mask,[1 1 size(img,3)]); masked_pixels = img(masknd); %extract into vector masked_pixels = reshape(masked_pixels, [nnz(mask), ones(1,ndims(img)-2), size(img,3)]); %reshape to rgb if needed equalized_masked = histeq(masked_pixels); eq_img = img; eq_img(masknd) = equalized_masked; subplot(1,2,2) h = imshow(eq_img); h.AlphaData = alphadata;
I suggest you consider using double(mask) as the AlphaData for imshow purposes. In particular, look at the shadows underneath the penguin: they are semi-transparent with alpha less than 1/2 so they are not included in equalization, but they do show up when using alphadata as the transparency mask -- which is done to be consistent with the transparency data stored in the original image.
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.