uint8 image solarization issue

8 visualizaciones (últimos 30 días)
Aaron Connell
Aaron Connell el 25 de Feb. de 2018
Comentada: Aaron Connell el 26 de Feb. de 2018
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.
b=imread('blocks.jpg');
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

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Feb. de 2018
comp_light_pixels = b;
mask = comp_light_pixels < 128;
comp_light_pixels(mask) = 255 - comp_light_pixels(mask);
  1 comentario
Aaron Connell
Aaron Connell el 26 de Feb. de 2018
this did not work unfortunately Sir. This is how I got it to work, but I thank you for the answer either way
the_image=imread('sample_image.png'); % read in the desired 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')
mask = y < 128; %only complement the pixels with grayscales less than 128, or the darker pixels
convert_mask=uint8(mask);
image=convert_mask.*y + (1-convert_mask).*(255-y);
subplot(2,2,3)
imshow(image)
title('Darker Pixels Are Complemented')
mask1=y > 128; %only complement the lighter pixels
convert_mask1=uint8(mask1);
image1=convert_mask1.*y + (1-convert_mask1).*(255-y);
subplot(2,2,4)
imshow(image1)
title('Lighter Pixels Are Complemented')
%%Question 1 Part C: Use the solarization functions on the bergen image.
the_image=imread('bergen.jpg'); % read in the desired 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
convert_mask2=uint8(mask2);
image2=convert_mask2.*y + (1-convert_mask2).*(255-y);
subplot(2,2,3)
imshow(image2)
title('Darker Pixels Are Complemented')
mask3=y > 128; %only complement the lighter pixels
convert_mask3=uint8(mask3);
image3=convert_mask3.*y + (1-convert_mask3).*(255-y);
subplot(2,2,4)
imshow(image3)
title('Lighter Pixels Are Complemented')

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by