How to avoid the information loss of image conversion from uint8 to logical and then back to uint8?

2 visualizzazioni (ultimi 30 giorni)
For example consider the image below, it is a jpeg in unint8 format.
In my code I require to process the image as unint8, then convert it to logical and then use it again in unint8 format. But apparently there is no way to get it back to its "as was" state. For example consider the following code:
image = imread('W1\Writer1_03_02.jpg');
bw_normal = im2bw(image, 0.1);
imshow(bw_normal);
It produces the following image:
Whichy shows that im2bw worked perfectly at 0.1 threshold. But if I convert it to logical and then back to unint8 and then perform the above command, the result is very different.
image = imread('W1\Writer1_03_02.jpg');
image = im2bw(image,graythresh(image));
image = im2uint8(image);
bw_normal = im2bw(image, 0.1);
imshow(bw_normal);
The result produced in this case was:
basically it did not work as intended. That is at every threshold increment or decrement the word shown in my image should grow or shrink respectively. But it does not happen that way once it is converted to logical and then back.
Is it possible to convert a logical image back in a way that works with im2bw according to how I expect it to like grow and shrink with threshold change?

Risposte (2)

Dishant Arora
Dishant Arora il 9 Apr 2014
graythresh(image) % check out the difference in threshold
Use the same threshold and you are going to get the same image.

Image Analyst
Image Analyst il 20 Set 2014
Once you've binarized the image you can't get back the information that you've thrown away. Basically you're finding out that the built-in automatic Otsu thresholding done by graythresh() is sometimes not very good. You need to pick the right threshold. In my File Exchange I have an interactive thresholding application. http://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image You can use that to threshold an image at the proper value but you still can't get back your original image from the logical, thresholded image.

Community Treasure Hunt

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

Start Hunting!

Translated by