How can I decrease intensity levels?

Hello,
I have RGB images and I got measurements for mean, max, min intensities. I want to decrease 20intensities from each shape in the image without limiting the highest value? For example if the shape has 85pixel at maximum, I want to make it 65, but the other shape has 110 , it should be 90. The blobs are in the same image, I split RGB, and working on only blue and green. Is that possible?
I attached function and one of my merged image, also my single command
Tugce2AnalyzeImage(originalImage, 20, 255)
Thank you
Tugce

Respuestas (2)

Image Analyst
Image Analyst el 21 de Sept. de 2022
Editada: Image Analyst el 21 de Sept. de 2022
Not sure what "limiting" means to you when talking about uint8 images. The values are limited by 0 so if the value is 15, subtracting 20 will give you 0, not -5. If you still want -5 then you need to cast the values to double. Otherwise you can simply do
[r, g, b] = imsplit(rgbImage);
b = b - 20;
g = g - 20;
rgbImage = cat(3, r, g, b);

1 comentario

Image Analyst
Image Analyst el 24 de Sept. de 2022
@Tugce Irem I'm still unsure after your comments to Walter what you mean by maximum and limiting. His code and my code both subtract 20, though his calls imclearborder and seems to call regionprops on the green gray scale image rather than a binary image. Anyway since you said that you know one image is just 20 gray levels higher than it should be due to some microscope glitch, why can't you just subtract 20 from the whole image (like Walter showed you at one point) or just only from the green and blue channels like you asked for and I showed you? What are we missing here?

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 21 de Sept. de 2022
newImg = imresize(Img, size(Img, 1:2)-20);

6 comentarios

Thank you both. I tried both suggestions, but unfortunately both of them removed some shapes but didn't reduce the pixels. I mean original code was recognizing 55 shapes, these code reconize 30-54 shapes in the same image and when I compare the images max intensities are still same in terms of the individual shapes (84 at the original and 84 at the new code), but some of shapes didn't recognized. Did I something wrong?
I copied my code with your suggestions
Thank you so much for the help
%copy the location and stitch the images
Controlmergedfiles = fullfile('C:\Users\A\Documents\MATLAB\Project\Control');
ControlmergedScene = imageDatastore(Controlmergedfiles,"FileExtensions",[".tif"]);
Controlmergedprimitiveim = montage(ControlmergedScene.Files);
Controlmerged = Controlmergedprimitiveim.CData;
[r, g, b] = imsplit(Controlmerged);
b = b - 20;
g = g - 20;
Controlmerged2 = cat(3, r, g, b);
% Extract color channels.
ControlmergedgreenChannelr = Controlmerged2 (:,:,2); % Green channel
ControlmergedblueChannelr = Controlmerged2 (:,:,3); % Blue channel
% Create an all black channel.
allBlackControlr = zeros(size(Controlmerged2, 1), size(Controlmerged2, 2), 'uint8');
Controlmergedjust_greenr = cat(3, allBlackControlr, ControlmergedgreenChannelr, allBlackControlr);
Controlmergedjust_bluer = cat(3, allBlackControlr, allBlackControlr, ControlmergedblueChannelr);
Controlmerged_green_bluerprimitiveim = montage({Controlmerged2, Controlmergedjust_greenr, Controlmergedjust_bluer});
Controlmerged_green_bluer = Controlmerged_green_bluerprimitiveim.CData;
%copy the location and stitch the images
Controlmergedfiles = fullfile('C:\Users\A\Documents\MATLAB\Project\Control');
ControlmergedScene = imageDatastore(Controlmergedfiles,"FileExtensions",[".tif"]);
Controlmergedprimitiveim = montage(ControlmergedScene.Files);
Controlmerged = Controlmergedprimitiveim.CData;
Controlmerged2 = imresize(Controlmerged, size(Controlmerged, 1:2)-20);
% Extract color channels.
ControlmergedgreenChannelr = Controlmerged2 (:,:,2); % Green channel
ControlmergedblueChannelr = Controlmerged2 (:,:,3); % Blue channel
% Create an all black channel.
allBlackControlr = zeros(size(Controlmerged2, 1), size(Controlmerged2, 2), 'uint8');
Controlmergedjust_greenr = cat(3, allBlackControlr, ControlmergedgreenChannelr, allBlackControlr);
Controlmergedjust_bluer = cat(3, allBlackControlr, allBlackControlr, ControlmergedblueChannelr);
Controlmerged_green_bluerprimitiveim = montage({Controlmerged2, Controlmergedjust_greenr, Controlmergedjust_bluer});
Controlmerged_green_bluer = Controlmerged_green_bluerprimitiveim.CData;
Walter Roberson
Walter Roberson el 21 de Sept. de 2022
For example if the shape has 85pixel at maximum, I want to make it 65
Do you mean that the shape is 85 pixels wide (or high) you want to reduce the shape to 65 pixels wide (or high) ?
Do you mean that the shape has a maximum intensity of 85 and you want to reduce the maximum intensity to 65? If so then do you want the intensities to scale linearly (so multiply each by 65/85) or do you want to subtract 20 from each intensity?
Is this all to be done on a shape-by-shape basis, with multiple shapes in the same image? Or when you say "shape" do you mean the entire image?
For example do you need to detect a coin and a ball on a background, and isolate them, and reduce their intensities by 20 each, and then re-insert the reduced-intensity objects back into the image with the background not having been reduced intensity ?
regionprops pixelidxlist or similar property can give you array of linear indices into the image. You can then do
YourMatrix(ind) = YourMatrix(ind) - 20;
Image Analyst
Image Analyst el 22 de Sept. de 2022
"I attached one of my images." <== Really? Where? I'm not seeing it. Of course, you should have done this right at the start, with your very first post.
And where in your code do you filter the blobs to extract or identify only the round ones?
If you have any more questions, then attach your image and code to read it in with the paperclip icon after you read this:
Thank you both, I tried to fixed the question, I attached the code. I was trying not to bother too much with my all codes, I was trying to ask specific question. Unfortunately Mr. Walter Roberson, I didn't understand how I can use this
YourMatrix(ind) = YourMatrix(ind) - 20;
Thanks again
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1134565/originalImage.jpg';
rgb = imread(filename);
imshow(rgb);
title('original')
r = rgb(:,:,1);
g = rgb(:,:,2);
b = rgb(:,:,3);
gborderless = imclearborder(g);
g_of_rgb = zeros(size(rgb), 'like', rgb);
g_of_rgb(:,:,2) = gborderless;
imshow(g_of_rgb);
title('green channel')
blobprops = regionprops(g, 'PixelIdxList');
all_used_idx = vertcat(blobprops.PixelIdxList);
r_filtered = r; r_filtered(all_used_idx) = r_filtered(all_used_idx) - 20;
g_filtered = g; g_filtered(all_used_idx) = g_filtered(all_used_idx) - 20;
b_filtered = b; b_filtered(all_used_idx) = b_filtered(all_used_idx) - 20;
rgb_filtered = cat(3, r_filtered, g_filtered, b_filtered);
imshow(rgb_filtered);
title('after intensity adjustment')

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing and Computer Vision en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 21 de Sept. de 2022

Comentada:

el 24 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by