imshow和imwrite显示在matlab中的空白图像 [英] Imshow and imwrite showing blank image in matlab

查看:206
本文介绍了imshow和imwrite显示在matlab中的空白图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像存储在数组中以进行分析.当我循环执行该过程并将结果写入"到各个文件中时,它将存储一个空白图像(与"imshow"相同). 当我在控制台上打印图像数组时,值应为它们的值(从50到200).这是我的部分代码出错.请帮助:

I am trying to store images in an array for some analysis. When I loop the process and 'imwrite' the result into various files, it stores a blank image (same for 'imshow' ). When I print the image array on console, the values are what should they be (varying from 50 to 200). Here's my part of code which goes wrong. Please help:

**必要的变量已在循环之前初始化.图像非空白.缩小图像是在打印'reduced_image(:,:,k);'时显示非零的数组但在inshow中显示空白图像.与"Img"变量相同.我尝试过使用像素的循环复制删除挤压功能,但是得到了相同的结果**

**Necessary variaables have been initialised before the loop. image is non-blank. reduced image is the array which shows non zero on printing 'reduced_image(:,:,k);' but shows blank image in inshow. Same for 'Img' variable. I have tried removing the squeeze function an use loopwise copying of pixel's, but that gave the same result **

for k=1:level
    for i=1:H/(2^k)
        for j=1:W/(2^k)
            reduced_image(i,j,k) = uint8 (( uint32(Image_current(2*i,2*j)) + uint32(Image_current(2*i - 1 ,2*j - 1)) )/2 ) ; 
        end
    end
    Img =  squeeze(reduced_image(:,:,k)) ;
    imwrite( Img , 'output.jpg' ) ;
end

推荐答案

有时是因为imshow尝试使用范围.

Sometime, It because imshow try to use a range.

只需尝试:

imshow(Img,[]);

迫使imshow使用当前范围的图像而无需重新缩放.

That force imshow to use the current range image without rescale it.

或者也许你可以做

imshow(Img,[50 200]);

但是,这会将您的图像重新缩放到0到25​​5之间(仅在显示屏上,该数组不会被修改).

But that will rescale your image to be between 0 and 255 (Just on the display, the array isn't modified).

编辑

要捕获显示图像,您可以执行以下操作:

To capture your display image you can do :

h = figure;
imshow(Img,[]);

saveas(h,'PathImage.jpg');

编辑2

标准化0-1之间并乘以255,以获得0到255的图像. Double Cast用于除法,而uint8用于恢复图像格式.

Normalize between 0 - 1 and multiply by 255 to get 0 to 255 image. Double cast is for the division and uint8 is to get back into image format.

maxVal = max(Img(:));
minVal = min(Img(:));

Img = uint8(255*double(double(Img(:) - minVal) / double( maxVal - minVal))));

这篇关于imshow和imwrite显示在matlab中的空白图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆