# uint8 image solarization issue

4 views (last 30 days)
Aaron Connell on 25 Feb 2018
Commented: DGM on 18 Jun 2024
Good afternoon I am trying to take a uint8 image and take the complement of all pixels with a grayscale less then 128 and again with all pixels with a grayscale greater than 128. This is an example of my attempt but I don't think it is working properly, if anyone could please give me a hand. I am supposed to create the two functions and then create a small test image to test the functions before applying them to an image but I don't know how to do that.
class(b)
comp_light_pixels=b<128 %only complement the lighter pixels of b
subplot(2,2,1)
imshow(comp_light_pixels) %show image with lighter pixels complemented
comp_dark_pixels=b>128 %only complement the darker pixels
subplot(2,2,2)
imshow(comp_dark_pixels) % show image with dark pixels complemented
subplot(2,2,3)
imshow(b) % show original image
subplot(2,2,4)
imshow(255-b) % show completely complemented image

Walter Roberson on 25 Feb 2018
comp_light_pixels = b;
Aaron Connell on 26 Feb 2018
this did not work unfortunately Sir. This is how I got it to work, but I thank you for the answer either way
y=uint8(the_image); % make sure image is uint8 before performing solarization
subplot(2,2,1)
imshow(y)
title('Original UINT8 Image')
subplot(2,2,2)
imshow(255-y)
title('Completely Complemented Image')
mask = y < 128; %only complement the pixels with grayscales less than 128, or the darker pixels
subplot(2,2,3)
imshow(image)
title('Darker Pixels Are Complemented')
mask1=y > 128; %only complement the lighter pixels
subplot(2,2,4)
imshow(image1)
title('Lighter Pixels Are Complemented')
%%Question 1 Part C: Use the solarization functions on the bergen image.
y=uint8(the_image); % make sure image is uint8 before performing solarization
subplot(2,2,1)
imshow(y)
title('Original UINT8 Image')
subplot(2,2,2)
imshow(255-y)
title('Completely Complemented Image')
mask2 = y < 128; %only complement the pixels with grayscales less than 128, or the darker pixels
subplot(2,2,3)
imshow(image2)
title('Darker Pixels Are Complemented')
mask3=y > 128; %only complement the lighter pixels
subplot(2,2,4)
imshow(image3)
title('Lighter Pixels Are Complemented')
DGM on 18 Jun 2024
Granted, it's not like "solarize" is really a well-defined transformation. That said, the given example still doesn't do what's probably expected.
% the image can only be uint8 class
% otherwise, everything will fail
x = uint8(0:255);
% only complement the pixels with grayscales less than 128, or the darker pixels
% only complement the lighter pixels
% plot the curves
plot(x,[y1;y2])
xlim([0 255])
ylim([0 255])
As is common, it's a hard vee curve, but neither case is full swing. That does mean that the contrast is preserved on either side of 50% gray, but I've never seen such an implementation, and have no idea why that would be a desirable interpretation.
This is a far simpler way to do the work. It's a more typical curve, and it's not blindly dependent on the input image class.
% some image in any class
x0 = uint8(0:255);
% put it in a consistent and convenient class and scale
x = im2double(x0);
% interpolate
tf = [0 1 0]; % hard vee curve
%tf = [1 0 1]; % inverted hard vee
y = interp1([0 0.5 1],tf,x,'linear');
% cast the output if you want it in some particular class
y = im2uint8(y);
% plot the curve
plot(x0,y)
xlim([0 255])
ylim([0 255])
The output curve is full swing, as is more typical. The input image can be of any typical numeric class.
% some image in any class
% put it in a consistent and convenient class and scale
inpict = im2double(inpict);
% interpolate
tf = [0 1 0]; % hard vee curve
%tf = [1 0 1]; % inverted hard vee
outpict = interp1([0 0.5 1],tf,inpict,'linear');
% cast the output if you want it in some particular class
outpict = im2uint8(outpict);
% display the result
imshow(outpict)
Of course, there are existing tools to do this.
% some image in any class
% solarize it (MIMT solarize())
%outpict = solarize(inpict,'vee'); % simple vee curve
outpict = solarize(inpict); % a nonlinear curve
% display the result
imshow(outpict)