How do u change the intensity ratio of the object in the gray scale image?
1 次查看(过去 30 天)
显示 更早的评论
Hi, there this is my first post in the communities, if I am not clear in the question description, please let me know. I am doing my best to give a precise description.
First of all, here is a dozen of gray-scale images. And one of them look like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162614/image.jpeg)
It has only one object in the image, and it might have different shapes and sizes. Assume it's total intensity I calculated is sum(sum(I)) = 25,000. I want to set a standard total intensity as 50,000. Thus I need to upscale the object and resize the image so it should look like the following image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162616/image.jpeg)
Please noted that the dimension/size of the image should stay the same, but the ratio the object takes in the image changes.
Any suggestion and hints would be greatly appreciated. Thank you all for your time and help!
0 个评论
回答(2 个)
Nut
2016-5-24
编辑:Nut
2016-5-24
Hi,
if all pixels outside the central region are zeros, I think you can solve this issue enlarging the entire image using the "imresize" functions: it should be possible to set the new dimensions starting from the total intensity you need. Then, you could use the "imcrop" function to cut the image and get back it with the same dimensions of the input image. Both functions are included in the Image Processing Toolbox.
If NOT all pixels outside the central region are zeros, you may need before to set a threshold intensity, to assign the value zero to all pixels with a value lower than the threshold.
I hope it is clear and helpful.
Image Analyst
2016-5-30
It's a little tricky and you won't get it right on the first try if you scale up by interpolating - you'll have to iterate if you need it exact. Here are the steps
- Get the intensity sum of the blob: initialSum = sum(grayImage(mask))
- Compute the scaling factor (desiredIntensitySum)/(initialSum)
- Put the image and that scaling factor into imresize().
- Find the centroid of the enlarged/shrunk blob and crop to desired size around it. Note that you may clip off edges of the blob if you had to enlarge it too much to get your desired intensity. It's not possible in all cases to both get the sum of the intensities to some desired value and be able to fit the whole blob in some specified rectangle. Like, what if the desired sum was 42 quadrillion? You'd have to enlarge that image so much that there is no way it would fit into, say, a 1k-by-1k image. And if you crop at 1k-by-1k then you won't have a sum of 42 quadrillion anymore.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!